chumsky icon indicating copy to clipboard operation
chumsky copied to clipboard

Add abstraction on top of the secondary error vector

Open Hedgehogo opened this issue 5 months ago • 1 comments

Make the type of secondary errors vector generic.

This will allow you to use smallvec or the arena in this location for optimization purposes, as well as use usize if the error is ZST.

It will also allow you to use a mutable reference, for example, to perform several compilation steps with a single vector of secondary errors, rather than alocating several and then concatenating. This will also require the ability to pass this reference accordingly when calling parse or one of its analogues.

Hedgehogo avatar Aug 17 '25 10:08 Hedgehogo

I am unconvinced that smallvec would actually be an optimisation. Vec only allocates when growing beyond its previous largest capacity, because it doesn't implicitly shrink. Therefore, the amortised cost of pushing a secondary error should be just a single capacity check (i.e: not meaningfully worse than the static size check for smallvec). Granted the memory is probably in another cache line, but if you're hitting secondary error generation enough that this matters, it's probably in cache already.

If you produce numbers that actually show a meaningful difference I'm willing to look into the issue, but I really don't want to be growing the API surface much for a trivial difference: chumsky is already too complex to use, in my view.

zesterer avatar Aug 18 '25 17:08 zesterer