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

Research object key iteration issues #16

Open
stevendesu opened this issue Nov 17, 2018 · 1 comment
Open

Research object key iteration issues #16

stevendesu opened this issue Nov 17, 2018 · 1 comment
Labels
question Further information is requested

Comments

@stevendesu
Copy link
Owner

Per #13, it was discovered that iterating over the keys in an object leads to intermittent performance issues. I suspect it is unexpectedly allocating memory and triggering garbage collection.

I need to do some research into what causes this so we can try to avoid it entirely. Maybe in the process I'll find a more efficient way to handle for...in that's even faster!

@stevendesu stevendesu added the question Further information is requested label Nov 17, 2018
@stevendesu
Copy link
Owner Author

While sitting in the shower yesterday I actually came up with a hypothesis that I believe explains this behavior, and I wish I'd written it down at the time instead of relying on my terrible memory to last 24 hours.

I know the gist of it came down to JavaScript being dynamically typed, and several compiler optimizations being type-dependent. Because arrays in JavaScript are not fixed width, they must be stored on the heap and not the stack. Therefore all elements within the array are pointers in the heap, not pointers in the stack. For non-objects, which are passed by value and not by reference, it is therefore necessary to create a copy whenever you perform an array access operation to avoid accidentally overwriting the value referenced by the pointer.

In my example I used integers in the array, which means that every time I modified the value I was actually secretly allocating new memory (to simulate pass-by-value for pointers on the heap). Because this library only supports arrays of objects (which are pass by reference) this may not be an issue in most cases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

1 participant