-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Question: can UglifyJS optimise order of dynamic enumerable property assignment? #2942
Comments
I think you may find enhancing Pull request is welcomed. |
I suspect I could only wish I had the required knowledge base to pull that off, but who knows? I'll have a look. Sounds like a rabbit hole full of edge-cases though... |
Changing the order of property creation would break code relying on iteration order. If this proposal is implemented it would have to be disabled by default.
|
I am expecting this feature to follow the same restrictions as |
The In any case, this proposal is out of scope for uglify - it does not reduce code size and would slow down minification. |
@kzc: oh, it definitely would be an |
If it's behind an |
I'm expecting the rearrangement would facilitate JavaScript runtime engines are constantly adjusting and improving to optimise against existing code in the wild anyway. |
That would be a different transform than the one proposed with a different goal. Assuming |
Sorry about the dense title, it's actually very simple to explain by example. In JavaScript, "object keys are iterated in insertion order (with a bizarre exception for arrays)"[0][1]. That results in JS engines treating
x
below as type-unstable¹, and because of that they are forced to generate less efficient code:In the linked presentation (from 2015), walking a splay tree was 15% faster after swapping the assignment order, so perf regressions can be quite big!
Based on the discussion in #75 I guess that UglifyJS can't do this currently, since it requires DFA.
EDIT: I see now that the discussion in that thread is years out of date, sorry! I guess there currently is some form of DFA already, given that
reduce_vars
,collapse_vars
andhoist_vars
exist?Still, it should be a little bit easier to determine when it is safe to change
x.b = E1; x.a = E2
tox.a = E2; x.b = E1
, than it would be to changevar x = E, y = E;
tovar x = E, y = x;
, pure functions don't have to return the same results (you can safely useMath.random()
forE1
andE1
, but not forE
).For anyone curious, I fell down this rabbit hole through the JITProf repository[2]. It's quite an interesting project but sadly it looks like it stalled.
¹ I borrowed the Julia concept "type stability", since I think it's more accessible than "
x
is polymorphic, even though it should be monomorphic and have only one hidden class".[0] http://mp.binaervarianz.de/fse2015_slides.pdf
[1] https://news.ycombinator.com/item?id=16416144
[2] https://github.com/Berkeley-Correctness-Group/JITProf
The text was updated successfully, but these errors were encountered: