Speed up toLocaleString
~2.5x by reducing creation of Intl.DateTimeFormat
instances by justingrant · Pull Request #12 · js-temporal/temporal-polyfill (original) (raw)
I would use
ES.HasOwnProperty()
here, to avoid calling getters a second time. That will still not quite be spec-compliant, since Proxy objects would be able to observe the HasProperty operation, but it's probably fine. Although that might mean we shouldn't backport this to proposal-temporal.
@ptomato I looked at the current polyfill code and I think that it has the multi-getter-call problem too. Look at the amend
function. I don't think the current polyfill has the Proxy problem because it ObjectAssign
s the options object before doing anything with it.
Anyway, I just pushed a new commit that does the options cloning (like the old polyfill) before reading, and also uses ES.HasOwnProperty()
to avoid making the proxy multi-getter problem any worse than it already is. I'll leave it for someone else to fix amend
later. Is this OK?
Also, I think this should be safe for back-porting because it doesn't make the current polyfill worse. What do you think?
LMK if you (or @ryzokuken @sffc) have any ideas how to improve this further.