[utils] add ArrayVec#3550
Conversation
Deploying with
|
| Status | Name | Latest Commit | Updated (UTC) |
|---|---|---|---|
| ✅ Deployment successful! View logs |
commonware-mcp | f53f4d9 | Apr 07 2026, 11:25 AM |
Deploying monorepo with
|
| Latest commit: |
f53f4d9
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://8ec5c483.monorepo-eu0.pages.dev |
| Branch Preview URL: | https://andre-stack-vec.monorepo-eu0.pages.dev |
There was a problem hiding this comment.
Is there a reason you opted to have our own implementation over using the arrayvec crate?
It also may be better to just use smallvec for this usecase, curious your thoughts. While it can spill over on to the heap unlike arrayvec / your impl, it should be roughly as efficient for the fixed size case while offering us a bit more flexibility to fit with often-small-but-dynamic cases as well.
There was a problem hiding this comment.
I don't really have an argument for not using arrayvec, in fact looking at it now the implementation is quite similar (although with a smaller API). I guess the only argument is that it's one less dependency to include, but I think arrayvec is probably already in our dependency tree (transitively). Will defer to @patrick-ogrady on this, am fine with just using arrayvec directly or just re-exporting it here.
I am worried that smallvec, or generally automatically spilling over to the heap, can mask pathological cases where you "thought" something was small but it actually isn't. smallvec is definitely more practical to use though.
There was a problem hiding this comment.
more flexibility to fit with often-small-but-dynamic cases as well
I guess this makes sense if it's just used as an optimization, where the size bound is more like a hint.
There was a problem hiding this comment.
Admittedly I haven't benchmarked smallvec vs. arrayvec when they're both in-bounds of the stack allocated array, though if they perform similarly, smallvec does provide an API we could use to create a wrapper type that panics when a spill-over is attempted.
That said, both are already in the monorepo's dependency tree. We could just re-export both crates' types?
|
related #2343 |
|
Thinking a bit more about this and after talking to @clabby, I think we should probably just re-export
|
Codecov Report❌ Patch coverage is
@@ Coverage Diff @@
## main #3550 +/- ##
========================================
Coverage 95.74% 95.74%
========================================
Files 438 439 +1
Lines 158111 158835 +724
Branches 3707 3725 +18
========================================
+ Hits 151382 152081 +699
- Misses 5543 5564 +21
- Partials 1186 1190 +4
... and 7 files with indirect coverage changes Continue to review full report in Codecov by Sentry.
🚀 New features to boost your workflow:
|
This PR adds
ArrayVec<T, N>, a fixed-capacity inline vector that stores up toNelements without heap-allocating the backing storage. This is useful for small, bounded buffers where the maximum length is known at compile time. Capacity is capped atu16::MAXto prevent accidentally large inline values. The type uses unsafe partial-initialization internally (to avoid aT: Defaultbound) but exposes a fully safe public API.The implementation covers the core
Vec-like surface:push,pop,insert,remove,swap_remove,resize,truncate,extend, iteration, and conversions to/fromVec, slices, and arrays. Anarray_vec!macro provides convenient construction with inferred capacity.