Skip to content
This repository has been archived by the owner on Jan 26, 2022. It is now read-only.

Performance of building objects #2

Open
bergus opened this issue Oct 2, 2019 · 1 comment
Open

Performance of building objects #2

bergus opened this issue Oct 2, 2019 · 1 comment

Comments

@bergus
Copy link

bergus commented Oct 2, 2019

The slides suggest that code like

const transformed = {};
for (const [k, v] of obj) {
    transformed[k.toLowerCase()] = v.toLowerCase();
}

"slowly builds up an object". What exactly is slow about this? Do users have performance problems with this? Is there engine implementor feedback that an Object.map function could have substantially improved it? And if yes, would that still be the case for an iterator-based dictionary aggregation solution?

(Just to kick off the discussion. Sorry if these were already brought up in the meeting and the answers will appear in the notes.)

@decompil3d
Copy link
Member

This is a good point. So my understanding is that when you slowly build up an object, many engines will, under the hood, produce native objects with all the fields you created thus far.

But you definitely make a valid point that the iterator-based approach doesn't help much here. The main reasoning of how Object.map solves this issue is that it makes developer intent more clear and thus allows engines to optimize more easily.

I'm curious to hear from implementors on this. Perhaps introducing something like the toObject method shown in the README would signal to engines that an object is being built from an iterated collection and should thus be optimized slightly differently (avoiding those hidden objects).

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants