macovedj opened PR #14706 from macovedj:component-async-table-capacity to bytecodealliance:main:
Component stream and future construction inserts a shared state and two endpoint handles into the resource table. If only one or two slots remain, construction can return
ResourceTableError::Fullafter inserting entries that the caller receives no handles to clean up. Failed construction therefore continues consuming table capacity.This PR checks the complete entry requirement before starting these allocations. It applies equivalent checks to guest tasks, explicit threads, and deferred host tasks, placing them before relevant task or task-group reference changes. Insufficient capacity then rejects the checked allocation batch before it creates partial entries.
It also adds constant-time
ResourceTable::len()and makes the existingis_empty()constant-time using centralized live-entry accounting. This supports repeated occupancy checks without scanning the backing table.
macovedj requested pchickey for a review on PR #14706.
macovedj requested wasmtime-core-reviewers for a review on PR #14706.
pchickey unassigned pchickey from PR #14706 Track live resources and preflight component async table allocations.
pchickey requested dicej for a review on PR #14706.
alexcrichton requested alexcrichton for a review on PR #14706.
alexcrichton unassigned dicej from PR #14706 Track live resources and preflight component async table allocations.
:memo: alexcrichton submitted PR review.
:speech_balloon: alexcrichton created PR review comment:
Personally I think this is too brittle to test for and isn't worth a test. I know LLMs are great at writing tests but I'd recommend still reviewing all tests and ruling subjectively whether it makes sense to include or not.
:speech_balloon: alexcrichton created PR review comment:
Similar to above -- how critical is this? This is a pretty complicated condition for a precise reservation, and in general once errors/traps happen the store is not really in a recoverable state.
:speech_balloon: alexcrichton created PR review comment:
Similar to above, I think this is too specific to have a unit test for here
:speech_balloon: alexcrichton created PR review comment:
Can these tests be rewritten to be independent of precise constants like this? This is quite brittle and will likely be annoying to change over time
:speech_balloon: alexcrichton created PR review comment:
How required is this? This seems like a pretty brittle check to have anything in front of and this seems like it would be quite easy to get out of sync in the future. For example the 2 here seems to clearly relate to at least one
pushbelow, but the other one I'm not sure whether it's innew_exlpcitoradd_guest_thread_to_instance_table.
:speech_balloon: alexcrichton created PR review comment:
This is a pretty huge test file for a pretty minor change -- are all of these tests necessary?
:speech_balloon: alexcrichton created PR review comment:
Instead of a loop here, could this be done with
self.entries.len() - self.live? That in theory should give the number of free slots somewhere in the linked list.
:speech_balloon: alexcrichton created PR review comment:
How come this is needed to reserve capacity for 1? Isn't that similar to a normal push?
:speech_balloon: alexcrichton created PR review comment:
It's ok to drop these, remember we don't test with features disabled
github-actions[bot] added the label wasmtime:api on PR #14706.
macovedj updated PR #14706.
:memo: macovedj submitted PR review.
:speech_balloon: macovedj created PR review comment:
If I'm not mistaken,
entries.len() - livewould count debug tombstones as free, since they’re excluded from live but aren’t available for reuse. I replaced the loop withfree_count, which is updated when slots enter or leave the free list. Please let me know if this doesn't feel any nicer or if you have other thoughts about a simpler approach.
:memo: macovedj submitted PR review.
:speech_balloon: macovedj created PR review comment:
Sorry about that. Won't happen again!
macovedj commented on PR #14706:
Thanks for the review! Removed a lot of the unnecessary checks/tests, and changed the while loop in
ensure_capacity. Apologies for the unneeded tests. I was in a hurry and should have been more judicious with them. I will be more mindful of this in future contributions!
:memo: alexcrichton submitted PR review.
:speech_balloon: alexcrichton created PR review comment:
This might be more naturally modeled as
checked_subrather thansaturating_sub
:speech_balloon: alexcrichton created PR review comment:
I think it's ok to drop the last sentence of "No table mutations..." here as that's pretty much implied. I also think it's ok to drop the "Debug tombstone..." comment since that's just an implementation detail
:speech_balloon: alexcrichton created PR review comment:
I'm a bit confused by this -- why have both
liveandfree_countif tombstones remain in thelivecount?
:speech_balloon: alexcrichton created PR review comment:
The
.saturating_subhere I think should be unnecessary, right?
:speech_balloon: alexcrichton created PR review comment:
This is only checking for 32-bit overflow, right? I think it's ok to skip that because in theory
max_capacityis where that limiting should happen if anywhere (and this is pretty niche)
:memo: alexcrichton submitted PR review.
:speech_balloon: alexcrichton created PR review comment:
Oh, also, mind moving this to
tests/all/*.rs? We don't typically put tests here in the wasmtime crate itself
macovedj updated PR #14706.
:memo: macovedj submitted PR review.
:speech_balloon: macovedj created PR review comment:
Good call. Thanks!
:memo: macovedj submitted PR review.
:speech_balloon: macovedj created PR review comment:
I think the collapsed diff/naming makes it hard to follow.
entryis the value that was just removed, so if a removed value is being replaced with a tombstone, it doesn't remain in thelivecount. The negative case here should only happen when attempting to remove anentrythat is already a tombstone. I renamed to try and make this clearer.
:memo: macovedj submitted PR review.
:speech_balloon: macovedj created PR review comment:
Yep sorry this won't happen again either.
:memo: macovedj submitted PR review.
:speech_balloon: macovedj created PR review comment:
I think with current behavior, if
max_capacityis set below the number of slots available, the free slots remain usable. So I think we should need it? Unless I"m missing something.
:memo: alexcrichton submitted PR review.
:speech_balloon: alexcrichton created PR review comment:
Ah good point!
:memo: alexcrichton submitted PR review.
:speech_balloon: alexcrichton created PR review comment:
Ah makes sense, thanks!
:thumbs_up: alexcrichton submitted PR review.
alexcrichton added PR #14706 Track live resources and preflight component async table allocations to the merge queue.
:check: alexcrichton merged PR #14706.
alexcrichton removed PR #14706 Track live resources and preflight component async table allocations from the merge queue.
Last updated: Oct 31 2026 at 23:03 UTC