<div dir="ltr"><div dir="ltr">On Thu, May 15, 2025 at 2:02 AM Peter Levart <<a href="mailto:peter.levart@gmail.com">peter.levart@gmail.com</a>> wrote:</div><div class="gmail_quote gmail_quote_container"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On 4/11/25 6:19 PM, Archie Cobbs wrote:<br>
> Sorry if that wasn't clear - I didn't mean power-of-two exponential <br>
> growth, I meant all segments were literally fixed size, like 256 or <br>
> something (or maybe this value would be provided to the constructor). <br>
> This keeps the access to individual elements constant time.<br>
<br>
You can have power-of-two exponentially growing segments and still <br>
access individual elements by index in constant time...</blockquote><div><br></div><div>Good point! There are more clever ways to size the chunks that still retain constant time access.</div><div><br></div></div><div>What I would love to see someday is all of this kind of cleverness baked into a standard set of "ArrayBuilder" classes, so we can then declare victory for cleverness and never have to worry about the fastest way to buffer data into memory again. Then we could focus our optimization efforts just on those classes, and the users of those classes all over the JDK (e.g., ArrayList, StringBuilder, whatever) would automatically benefit.</div><div><br></div><div>This might be a pipe dream. At least, it brings up an interesting question re: how you would design such a thing... e.g., how would you parameterize it? E.g., Initial chunk size, maximum chunk size, growth rate exponent, etc. Or could it be truly adaptive (one (initial) size fits all)? Etc.</div><div><br></div><div>-Archie</div><br><span class="gmail_signature_prefix">-- </span><br><div dir="ltr" class="gmail_signature">Archie L. Cobbs<br></div></div>