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

Improve HelperMap.has performance #239

Merged
merged 3 commits into from
May 13, 2017
Merged

Improve HelperMap.has performance #239

merged 3 commits into from
May 13, 2017

Conversation

jlukic
Copy link
Contributor

@jlukic jlukic commented Mar 9, 2017

The in keyword in javascript is notoriously slow in javascript.

In FF in performs approximately ~300x slower, chrome ~0.3x slower depending on test.

I originally noticed this method popping up a bunch in CPU profiles for a meteor app.

This PR replaces HelperMap.has with what should be a faster method of accessing existence.

Some perfs
https://jsperf.com/hasownproperty-vs-in-vs-undefined/12
https://jsperf.com/checking-if-a-property-exists/10

As an aside, typecasting with '' + value (the existing setup) is the most performant way
https://jsperf.com/convert-to-string-bj/3

The `in` keyword in javascript is notoriously slow in javascript.

This PR replaces `HelperMap.has` with what appears to be fastest method of accessing existence.

In FF `in` performs approximately ~300x slower, chrome ~0.3x slower depending on test

(Not my perfs)
https://jsperf.com/hasownproperty-vs-in-vs-undefined/12
https://jsperf.com/checking-if-a-property-exists/10
@apollo-cla
Copy link

@jlukic: Thank you for submitting a pull request! Before we can merge it, you'll need to sign the Meteor Contributor Agreement here: https://contribute.meteor.com/

@mitar
Copy link
Contributor

mitar commented Mar 9, 2017

Hm, interesting. But how often is this called? Only when one defined helpers on a template? This is not often, no?

@jlukic
Copy link
Contributor Author

jlukic commented Mar 10, 2017

My understanding is that lookup checks for template helpers 2nd in lookup list - Line 162

if (template && ((helper = Blaze._getTemplateHelper(template, name, boundTmplInstance)) != null)) {

getTemplateHelper immediately checks if this is a helper - Line 40

if (template.__helpers.has(name)) {

So anything that hits 2+ in lookup: i.e lexical scope, data context has to hit this function, which is why it gets called a lot.

@mitar
Copy link
Contributor

mitar commented Mar 10, 2017

Ooo, good good. :-)

One more thing. Should we just replace that map with ES6 Map? And use ecmascript package to polyfill it? I am not sure about performance in this case, but probably it should be cleaner?

@arggh
Copy link

arggh commented May 13, 2017

Is this PR missing something? Any performance improvements would be most welcome.

@mitar
Copy link
Contributor

mitar commented May 13, 2017

Yes. We can merge this.

@mitar mitar merged commit 956709d into meteor:master May 13, 2017
@mitar
Copy link
Contributor

mitar commented May 13, 2017

Thanks!

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

Successfully merging this pull request may close these issues.

4 participants