Skip to content

V2: Avoid JIT deoptimizations#836

Merged
timostamm merged 2 commits intov2from
tstamm/avoid-deopt
May 10, 2024
Merged

V2: Avoid JIT deoptimizations#836
timostamm merged 2 commits intov2from
tstamm/avoid-deopt

Conversation

@timostamm
Copy link
Member

Following #834, we can make another - but smaller - performance improvement by avoiding a couple of deopts in v8:

- fromBinary perf-payload.bin x 4,548 ops/sec ±0.54% (93 runs sampled)
+ fromBinary perf-payload.bin x 5,094 ops/sec ±0.51% (97 runs sampled)

"generate:js": "protoc --es_out=src/gen/js --es_opt=ts_nocheck=false,target=js+dts,import_extension=.js --proto_path=. $(buf ls-files extra) --proto_path=$(upstream-include test) $(upstream-files test) google/protobuf/type.proto",
"postgenerate": "license-header src/gen",
"perf": "tsx src/perf.ts benchmark '.*'",
"profile": "dexnode dist/esm/perf.js run 'fromBinary perf-payload.bin' 10000",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The resulting logs can be inspected with the deopt explorer. Seems worth keeping this script and dep.

// eslint-disable-next-line no-case-declarations
const [key, val] = readMapEntry(field, reader, options);
message.setMapEntry(field, key, val);
readMapEntry(message, field, reader, options);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoiding an eager bailout here.

Comment on lines +796 to +799
listKind: undefined,
mapKind: undefined,
mapKey: undefined,
delimitedEncoding: undefined,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding these properties means that the JIT can use the same map. It adds some bytes to the bundle size, but that's always the trade-off. I think it's worth it here for the >10% gain.

@timostamm timostamm requested a review from srikrsna-buf May 10, 2024 09:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants