Skip to content
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

V2: Avoid JIT deoptimizations #836

Merged
merged 2 commits into from
May 10, 2024
Merged

V2: Avoid JIT deoptimizations #836

merged 2 commits into from
May 10, 2024

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)

@@ -13,6 +13,7 @@
"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.

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