Skip to content

Conversation

@MaxGraey
Copy link
Member

@MaxGraey MaxGraey commented Apr 30, 2021

Fix #1798

  • Now internal capacity growing by factor of two.
  • Initial capacity changed from 0 to 8 elements

Performance results for sequentially push 1,000,000 items into empty i32 array (--runtime=incremental)

Browser master
ms
this PR
ms
JavaScript's Array
(baseline), ms
Firefox 88 61557 7 10
Chrome 90 69552 8 11.4
  • I've read the contributing guidelines

@MaxGraey MaxGraey requested a review from torch2424 May 1, 2021 09:42
@dcodeIO
Copy link
Member

dcodeIO commented May 1, 2021

Two things:

  • Skip doubling when setting .length, as it doesn't typically imply a series of .pushes coming afterwards. Memory is precious.
  • Account for the case where doubling would overflow maximum block size, and cap to maximum valid block size there. Otherwise growing at half maximum block size would always fail. Probably also needs a check that after all these computations, the new size is actually larger or equal to the originally requested capacity before doubling/capping, so we don't end up with a corrupted object.

@trusktr
Copy link
Member

trusktr commented May 1, 2021

Wow, big speed up!

@MaxGraey MaxGraey merged commit ca02a7d into AssemblyScript:master May 3, 2021
@MaxGraey MaxGraey deleted the fix-array-push branch May 3, 2021 14:16
MaxGraey added a commit that referenced this pull request May 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

~lib/array/Array#push is unnecessarily garbage-y

3 participants