smarr / are-we-fast-yet

Are We Fast Yet? Comparing Language Implementations with Objects, Closures, and Arrays
Other
334 stars 36 forks source link

Lazily initialize backing store of Vector #90

Closed smarr closed 7 months ago

smarr commented 7 months ago

During the discussion of https://github.com/smarr/are-we-fast-yet/pull/84 the initialization strategy of Vector was discussed. Before this PR, it would create an array of 50 elements in the default case.

This PR changes Vector to not create an array at the beginning, and instead initialize the storage with null. The access operations are adapted to check for null where needed and initialize the storage array on demand.

The size of the initial array is also decreased to 10. This choice is made mostly based on results from large program corpuses where people found that arrays tent to be small, usually have few elements. Though, I didn't investigate what the size distribution for our benchmarks here is.

The PR also has a few other minor cleanups.