Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Array initialization pattern for packed arrays is sub-optimal on v8 #4805

Open
gzm0 opened this issue Feb 6, 2023 · 1 comment
Open

Array initialization pattern for packed arrays is sub-optimal on v8 #4805

gzm0 opened this issue Feb 6, 2023 · 1 comment
Labels
optimization Optimization only. Does not affect semantics or correctness.

Comments

@gzm0
Copy link
Contributor

gzm0 commented Feb 6, 2023

Follow-up to #4736

One last follow-up: I installed d8 (debug v8) as suggested in the linked blog post.

$ ~/.jsvu/bin/v8-debug 
V8 version 11.1.192
d8> 

I was able to replicate their example:

const array = [1, 2, 3];
array[3] = 4.56;
$ ~/.jsvu/bin/v8-debug --trace-elements-transitions test.js 
elements transition [PACKED_SMI_ELEMENTS -> PACKED_DOUBLE_ELEMENTS] in ~+15 at test.js:1 for 0x0e520010b461 <JSArray[3]> from 0x0e520025a3c1 <FixedArray[3]> to 0x0e520010b471 <FixedDoubleArray[22]>

But if I initialize elements one-by-one, then the initial state becomes HOLEY_SMI_ELEMENTS.

const array = new Array(3);
array[0] = 1;
array[1] = 2;
array[2] = 3;
array[3] = 4.56;
elements transition [HOLEY_SMI_ELEMENTS -> HOLEY_DOUBLE_ELEMENTS] in ~+60 at test.js:1 for 0x02d60010b48d <JSArray[3]> from 0x02d60010b49d <FixedArray[3]> to 0x02d60010b4b1 <FixedDoubleArray[22]>

So unfortunately this is a sub-optimal initialization pattern on V8.

Originally posted by @armanbilge in #4736 (comment)

@gzm0
Copy link
Contributor Author

gzm0 commented Feb 6, 2023

This was in my email backlog for a while but it really should be in the Scala.js backlog :)

@sjrd sjrd added the optimization Optimization only. Does not affect semantics or correctness. label Feb 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
optimization Optimization only. Does not affect semantics or correctness.
Projects
None yet
Development

No branches or pull requests

2 participants