-
Notifications
You must be signed in to change notification settings - Fork 26.3k
Buffer in Pickler to improve performance. #27720
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
This pull request was exported from Phabricator. Differential Revision: D17847174 |
496b083 to
150e5c7
Compare
|
This pull request was exported from Phabricator. Differential Revision: D17847174 |
Summary: Pull Request resolved: pytorch#27720 This change adds a small fixed-size buffer to Pickler to avoid calling writer_() and the associated downstream checks on a per-opcode/per-byte basis. We end up still doing a bounds check in the common case, but the memcpy() is a fixed size. And we reduce the number of backend calls. In practice, this change speeds up the Pickle1MInts benchmark for me locally from roughly 56msec to 22msec. Additionally, in this change we convert a few pushIValue() on typed lists, where we know the type to be double/int/boot to be pushInt() to bypass a bit of logic. We should additionally change the Unpickler, though keeping this separate, since the std::function<> prototype needs to be changed for this to work (i.e. return size_t rather than bool). Test Plan: buck test mode/dev-nosan caffe2/test:... Benchmark in experimental/jeremyl/c2/SerializationBench.cpp (run in mode/opt) Differential Revision: D17847174 fbshipit-source-id: 30eace0187f71d9fff13a53013227b780f93c6c0
150e5c7 to
fd49e74
Compare
|
This pull request was exported from Phabricator. Differential Revision: D17847174 |
zdevito
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, thanks!
facebook-github-bot
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jjlilley is landing this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
|
Would you mind stamping #28043 ? I used the web-based export-from-phabricator originally with this diff, which alas is suffering from an Infra failure, and apparently using the web tool makes ghexport not work. The change 28043 is identical except that I addressed the two pending review comments:
Thanks! |
Summary: This change adds a small fixed-size buffer to Pickler to avoid calling writer_() and the associated downstream checks on a per-opcode/per-byte basis. We end up still doing a bounds check in the common case, but the memcpy() is a fixed size. And we reduce the number of backend calls. In practice, this change speeds up the Pickle1MInts benchmark for me locally from roughly 56msec to 22msec. Additionally, in this change we convert a few pushIValue() on typed lists, where we know the type to be double/int/boot to be pushInt() to bypass a bit of logic. We should additionally change the Unpickler, though keeping this separate, since the std::function<> prototype needs to be changed for this to work (i.e. return size_t rather than bool). Pull Request resolved: pytorch#27720 Test Plan: buck test mode/dev-nosan caffe2/test:... Benchmark in experimental/jeremyl/c2/SerializationBench.cpp (run in mode/opt) Differential Revision: D17847174 Pulled By: jjlilley fbshipit-source-id: 22e5e5fd33f1a369c124ea5aac7880538e2bf6a0
Summary:
This change adds a small fixed-size buffer to Pickler to
avoid calling writer_() and the associated downstream checks
on a per-opcode/per-byte basis.
We end up still doing a bounds check in the common case,
but the memcpy() is a fixed size. And we reduce the number
of backend calls.
In practice, this change speeds up the Pickle1MInts benchmark
for me locally from roughly 56msec to 22msec.
Additionally, in this change we convert a few pushIValue() on
typed lists, where we know the type to be double/int/boot to be
pushInt() to bypass a bit of logic.
We should additionally change the Unpickler, though keeping
this separate, since the std::function<> prototype needs to be
changed for this to work (i.e. return size_t rather than bool).