3 ms·
You don't need to prove it, you just need to guess it successfully. If you're wrong you can deoptimise and fix-up to the same base-line performance.
by chrisseaton 8y ago
You don't need to prove it, you just need to guess it successfully. If you're wrong you can deoptimise and fix-up to the same base-line performance.
- chii 8y ago> If you're wrong you can deoptimise and fix-up to the same base-line performance. but how do you know it's wrong (if the iteration order of a .keys() call isnt the same)?
- fasquoika 8y agoThe original code didn't have a call to .keys(), and that's the case where this should be optimized. If you do the unordered optimization, then encounter an operation that needs an ordered iteration, you'd have to fall back to an ordered representation (which could be slower than not doing the optimization at all)
- MikeHolman 8y agoThat requires extra bookkeeping for ordering, but it isn't really that common where people will have object literals with the same properties initialized in a different order. But a much more common case is that properties added after object creating will be added in an inconsistent order, for example: o = {}; o.x = 1; o.y = 2; o.z = 3; p = {}; p.y = 4; p.x = 5; p.z = 6; When executing p.y = 4 you don't know that the object will eventually evolve to have the same properties as o.
- gsnedders 8y agoThat would surely be the second option? Treating all permutations the same means changing the object representation to keep ICs monomorphic across orderings. Unless you forbid any impure operations you can't just deoptimise and re-execute code to then store the ordering. (I'm sure this isn't what you meant, and I'm probably being silly!)