Repository navigation
fix(husk): charge shared arrays and maps once against the plugin heap - #399
Merged
Merged
Conversation
Every cell holding an Arc-shared array was charged its full size, so a plugin holding a 30 MB list could not pass it to a helper. Count shared storage once, with a holder count, and charge cells only for the value itself. Writes still copy and are still charged. Fixes #395
Contributor
Author
|
@codex review |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 705e7dc099
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
…nment heap_value_size left out a struct's type name, which the shared-storage charge includes, so a host result sized to the free heap could pass the preflight check and fail allocation. Reassignment also cloned the old value, a deep copy for strings and JSON.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #395.
Why
The Husk runtime charged every variable, parameter and captured value the full size of what it held. Arrays and maps are shared (
Arc), so passing one to a function copies nothing. But each new binding was still charged the whole list again. A plugin holding a 25 MB list could not pass it to a helper: four bindings meant 100 MB against a 64 MiB heap. The errors looked like real memory exhaustion, andlsp_symbolshad to work around them (#388, #393).What changed
push, index or field assignment) works on a copy, because the cell and the table both hold the original. That copy is new storage and is charged in full, so the limit still bounds real memory. The table holds a clone of each countedArc, so a counted address can't be reused while it's in the table.heap_value_sizenow counts a struct's type name, as it already did for variants, so it matches the new charge exactly. The comments on it andheap_cell_sizenow say thatheap_cell_sizeis the exact charge for a value no cell shares yet, such as a host result, which is the number the fix(plugins): trim or drop request results too large for a plugin's heap #398 budget check uses. Inlsp_symbols.hkI removed the comments blaming per-binding charges. The 4,096-record slicing stays, because pickers show at most that many rows.The deterministic performance gate (
husk_cursor_bench) is unchanged within noise: p50 789 µs before, 797 µs after, on the same machine.How to Test
Save this as
shared.hk. It builds one ~25 MB list of 800 strings of 32 KiB each and holds it in four bindings:Run
cargo run -p husk-cli -- run shared.hk. It exits with status 0 and no output. Onmainit fails atreport(copy, items)withHusk heap byte limit exceeded (requested 26284976 bytes with 52674082 of 67108864 bytes live).Regression check, the limit still holds: save this as
runaway.hk. It pushes a 1 MiB string 100 times, so every push makes a new, larger list:cargo run -p husk-cli -- run runaway.hkstill fails withHusk heap byte limit exceeded (value needs 66065920 bytes …).Optional: open a large TypeScript project and press
Space w. The workspace symbol picker behaves as after fix(plugins): trim or drop request results too large for a plugin's heap #398.New tests in
husk-runtime:shared_array_is_charged_once_however_many_cells_hold_it: one array held by six cells across two frames fits a heap sized for one copy. It also checks that all its memory is released afterwards.copying_a_shared_array_to_change_it_is_charged: apushon a shared array is charged as a full copy. After the failed write, nothing has leaked.growing_an_array_past_the_heap_limit_still_failsunshared_value_is_charged_exactly_its_heap_value_size: for a value no cell shares yet, such as a host result, the charge equalsheap_cell_size, the number the fix(plugins): trim or drop request results too large for a plugin's heap #398 budget check relies on.The first two fail on
main.