When snocing to a Builder which has no right node, instead of allocating a new Builder, we could just mutate the current Builder’s ArrayBuffer.
We could also add an effectful preallocate function which would allow us to grow the Builder’s ArrayBuffer in advance of doing a lot of snocing, in the event that we have a good idea of how much snocing we're about to do.
So when we're doing a build which involves a lot of snocs of bytes, then instead of allocating a new ArrayBuffer for each byte as we do now, we could get close to the ideal performance case of just allocating one ArrayBuffer and then mutating it. And this would keep the same API, but with addition of a preallocate function. And we would still get the same performance advantages for doing a subBuilder with our unbalanced binary tree.
When
snocing to aBuilderwhich has no right node, instead of allocating a newBuilder, we could just mutate the currentBuilder’sArrayBuffer.We could also add an effectful
preallocatefunction which would allow us to grow theBuilder’sArrayBufferin advance of doing a lot of snocing, in the event that we have a good idea of how much snocing we're about to do.So when we're doing a build which involves a lot of snocs of bytes, then instead of allocating a new
ArrayBufferfor each byte as we do now, we could get close to the ideal performance case of just allocating oneArrayBufferand then mutating it. And this would keep the same API, but with addition of apreallocatefunction. And we would still get the same performance advantages for doing asubBuilderwith our unbalanced binary tree.