Skip to content

perf: use v8::Local<v8::Object> as the key in ObjectCache - #43519

Merged
ckerr merged 2 commits into
mainfrom
perf/object-proxy-cache
Sep 5, 2024
Merged

ckerr merged 2 commits into
mainfrom
perf/object-proxy-cache

Conversation

@ckerr

@ckerr ckerr commented Aug 31, 2024 •

Copy link
Copy Markdown
Member

Description of Change

Followup to #27639

This cache is a v8::Object-to-v8::Local<v8::Value> lookup.

We're currently using v8::Local<v8::Object> as the key in a two-step process: first we hash the object as a std::unordered_map key. Second, we walk through a linked list of previously-cached v8::Local<v8::Object>s looking for one that matches our key. Handles check for equality via v8::HandleHelper::EqualHandles(), so this is basically just testing pointers for equality (a.ptr() == b.ptr()).

This PR skips the middle steps and just uses a v8::Object* v8::Local<v8::Object> as the key

Checklist

Release Notes

Notes: none.

@ckerr ckerr added performance 🏁 semver/patch backwards-compatible bug fixes labels Aug 31, 2024
@electron-cation electron-cation Bot added the new-pr 🌱 PR opened recently label Aug 31, 2024
@ckerr ckerr changed the title perf: use v8::Object* as direct keys instead of using hash + linked list perf: use v8::Object* as direct keys in ObjectCache Aug 31, 2024
@ckerr ckerr changed the title perf: use v8::Object* as direct keys in ObjectCache perf: use v8::Object* as the key in ObjectCache Aug 31, 2024

@MarshallOfSound MarshallOfSound left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think I thought about this when writing ctx bridge originally, the theory was that concurrent marking / GC could do strange thing if we keyed off of pointer instead of the underlying object hash as the object could move within the heap during a single ctx bridge evaluation.

@ckerr

ckerr commented Aug 31, 2024 •

Copy link
Copy Markdown
Member Author

@MarshallOfSound you're right; this PR will break in IndirectHandleBase if the internal::Address pointer changes.

Using a Local ptr or slot as a map key is fundamentally unsafe

@ckerr
ckerr marked this pull request as draft August 31, 2024 12:33
@ckerr

ckerr commented Aug 31, 2024 •

Copy link
Copy Markdown
Member Author

Updated to use v8::Local<v8::Object> as the Key type for the unordered map.

Note, we don't need to provide a custom KeyEqual for the unordered set because v8::Local's equality operators are already good

@ckerr
ckerr marked this pull request as ready for review August 31, 2024 19:37
@ckerr
ckerr requested a review from MarshallOfSound August 31, 2024 19:37
@ckerr
ckerr force-pushed the perf/object-proxy-cache branch 2 times, most recently from 6b26c8e to 1e9ba49 Compare August 31, 2024 19:45
@electron-cation electron-cation Bot removed the new-pr 🌱 PR opened recently label Sep 1, 2024
@ckerr ckerr changed the title perf: use v8::Object* as the key in ObjectCache perf: use v8::Local<v8::Object> as the key in ObjectCache Sep 2, 2024
@codebytere
codebytere force-pushed the perf/object-proxy-cache branch from b3303ed to dbb06fa Compare September 4, 2024 10:25
@ckerr ckerr added target/31-x-y PR should also be added to the "31-x-y" branch. target/32-x-y PR should also be added to the "32-x-y" branch. target/33-x-y PR should also be added to the "33-x-y" branch. labels Sep 5, 2024
@ckerr
ckerr merged commit 2d868ec into main Sep 5, 2024
@release-clerk

release-clerk Bot commented Sep 5, 2024

Copy link
Copy Markdown

No Release Notes

@ckerr
ckerr deleted the perf/object-proxy-cache branch September 5, 2024 03:53
@trop

trop Bot commented Sep 5, 2024

Copy link
Copy Markdown
Contributor

I was unable to backport this PR to "31-x-y" cleanly;
you will need to perform this backport manually.

@trop

trop Bot commented Sep 5, 2024

Copy link
Copy Markdown
Contributor

I was unable to backport this PR to "32-x-y" cleanly;
you will need to perform this backport manually.

@trop trop Bot added needs-manual-bp/31-x-y and removed target/31-x-y PR should also be added to the "31-x-y" branch. target/32-x-y PR should also be added to the "32-x-y" branch. labels Sep 5, 2024
@trop

trop Bot commented Sep 5, 2024

Copy link
Copy Markdown
Contributor

I have automatically backported this PR to "33-x-y", please check out #43568

@trop trop Bot added in-flight/33-x-y merged/33-x-y PR was merged to the "33-x-y" branch. and removed target/33-x-y PR should also be added to the "33-x-y" branch. in-flight/33-x-y labels Sep 5, 2024
@trop

trop Bot commented Sep 10, 2024

Copy link
Copy Markdown
Contributor

@codebytere has manually backported this PR to "32-x-y", please check out #43662

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merged/31-x-y PR was merged to the "31-x-y" branch. merged/32-x-y PR was merged to the "32-x-y" branch. merged/33-x-y PR was merged to the "33-x-y" branch. performance 🏁 semver/patch backwards-compatible bug fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants