Skip to content

Conversation

@jjlilley
Copy link

@jjlilley jjlilley commented Oct 15, 2019

Stack from ghstack:

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 to do buffering (return value needs to change from bool
to size_t)

Differential Revision: D17939311

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 to do buffering (return value needs to change from bool
to size_t)

Differential Revision: [D17939311](https://our.internmc.facebook.com/intern/diff/D17939311/)

[ghstack-poisoned]
@jjlilley jjlilley requested a review from apaszke as a code owner October 15, 2019 21:23
@facebook-github-bot facebook-github-bot added the oncall: jit Add this issue/PR to JIT oncall triage queue label Oct 15, 2019
jjlilley pushed a commit that referenced this pull request Oct 15, 2019
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 to do buffering (return value needs to change from bool
to size_t)

Differential Revision: [D17939311](https://our.internmc.facebook.com/intern/diff/D17939311/)

ghstack-source-id: 91964964
Pull Request resolved: #28043
@jjlilley jjlilley requested review from resistor and zdevito October 16, 2019 00:09
@jjlilley jjlilley changed the title [pytorch] Double-buffer in Pickler to reduce #calls. [pytorch] Buffer in Pickler to improve performance. Oct 16, 2019
@jjlilley
Copy link
Author

This change is identical to (approved) 27720, except that

  • I added a static assert per the review comments.
  • the one-line TODO comment related to the LONG4 is removed

There was a tooling failure this afternoon which made it tricky for me to update 27720 (particularly, I used the web-based export-from-phabricator rather than ghexport, which has an infra issue now, and precludes using ghexport on followup diffs).

If it's possible to stamp this, that would be great!

@jjlilley jjlilley closed this Oct 16, 2019
@facebook-github-bot facebook-github-bot deleted the gh/jjlilley/2/head branch November 16, 2019 15:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

oncall: jit Add this issue/PR to JIT oncall triage queue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants