Skip to content

feat(allocator): FixedSizeAllocator store flag recording if owned by both Rust and JS#12381

Merged
graphite-app[bot] merged 1 commit intomainfrom
07-17-feat_allocator_fixedsizeallocator_store_flag_recording_if_owned_by_both_rust_and_js
Jul 18, 2025
Merged

feat(allocator): FixedSizeAllocator store flag recording if owned by both Rust and JS#12381
graphite-app[bot] merged 1 commit intomainfrom
07-17-feat_allocator_fixedsizeallocator_store_flag_recording_if_owned_by_both_rust_and_js

Conversation

@overlookmotel
Copy link
Member

@overlookmotel overlookmotel commented Jul 18, 2025

Add a field is_double_owned to FixedSizeAllocatorMetadata. This field tracks ownership of the allocator/buffer. It's true if both Rust and JS currently hold a reference to the memory, or false if only one does.

Drop impl for FixedSizeAllocator checks the value of this field and only frees the memory if JS doesn't also hold a reference.

At present, is_double_owned is always false, because we're not transferring buffers over to JS yet. But it'll come into play in later PR. At that point the finalizer which runs when JS garbage collector collects the buffer will also update is_double_owned, and free the memory if Rust already dropped the FixedSizeAllocator, so JS is the only remaining owner.

Copy link
Member Author

overlookmotel commented Jul 18, 2025


How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • 0-merge - adds this PR to the back of the merge queue
  • hotfix - for urgent hot fixes, skip the queue and merge this PR next

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

@codspeed-hq
Copy link

codspeed-hq bot commented Jul 18, 2025

CodSpeed Instrumentation Performance Report

Merging #12381 will not alter performance

Comparing 07-17-feat_allocator_fixedsizeallocator_store_flag_recording_if_owned_by_both_rust_and_js (b0db2d7) with main (de006a1)

Summary

✅ 34 untouched benchmarks

Copy link
Contributor

camc314 commented Jul 18, 2025

Merge activity

@graphite-app graphite-app bot removed the 0-merge Merge with Graphite Merge Queue label Jul 18, 2025
…y both Rust and JS (#12381)

Add a field `is_double_owned` to `FixedSizeAllocatorMetadata`. This field tracks ownership of the allocator/buffer. It's `true` if both Rust and JS currently hold a reference to the memory, or `false` if only one does.

`Drop` impl for `FixedSizeAllocator` checks the value of this field and only frees the memory if JS doesn't also hold a reference.

At present, `is_double_owned` is always `false`, because we're not transferring buffers over to JS yet. But it'll come into play in later PR. At that point the finalizer which runs when JS garbage collector collects the buffer will also update `is_double_owned`, and free the memory if Rust already dropped the `FixedSizeAllocator`, so JS is the only remaining owner.
@graphite-app graphite-app bot force-pushed the 07-16-feat_allocator_allocatorpool_store_ids_in_allocator_s branch from 43b0114 to bc0fbe5 Compare July 18, 2025 09:00
@graphite-app graphite-app bot requested a review from camc314 as a code owner July 18, 2025 09:00
@graphite-app graphite-app bot force-pushed the 07-17-feat_allocator_fixedsizeallocator_store_flag_recording_if_owned_by_both_rust_and_js branch from 90fb884 to b0db2d7 Compare July 18, 2025 09:01
Base automatically changed from 07-16-feat_allocator_allocatorpool_store_ids_in_allocator_s to main July 18, 2025 09:11
@graphite-app graphite-app bot merged commit b0db2d7 into main Jul 18, 2025
26 checks passed
@graphite-app graphite-app bot deleted the 07-17-feat_allocator_fixedsizeallocator_store_flag_recording_if_owned_by_both_rust_and_js branch July 18, 2025 09:13
graphite-app bot pushed a commit that referenced this pull request Jul 21, 2025
`AtomicBool::store` does the same as `fetch_and(false)` / `fetch_or(true)`, is simpler, and possibly a little bit cheaper. Not sure why I didn't use it in the first place in #12381!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C-enhancement Category - New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants