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

Replace forEach with for loop in runStringHandlers #208

Merged
merged 2 commits into from
Mar 6, 2017

Conversation

lencioni
Copy link
Collaborator

@lencioni lencioni commented Mar 5, 2017

According to my profiling, this seems to make runStringHandlers about
10% faster.

Copy link
Contributor

@xymostech xymostech left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, but we're avoiding vars, so one little nit

src/generate.js Outdated
Object.keys(declarations).forEach(key => {
const hasStringHandlers = !!stringHandlers;
const keys = Object.keys(declarations);
for (var i = 0; i < keys.length; i += 1) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let i = 0 maybe? Is that slower?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops! Should be the same speed, since I think babel compiles it down to var. I think all of the error checking related to the block scoping happens at build time.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed!

lencioni added 2 commits March 6, 2017 14:01
According to my profiling, this seems to make runStringHandlers about
10% faster.
Profiling in Chrome shows that moving this out of the loop makes this
function ~30% faster.
@lencioni lencioni force-pushed the runstringhandlers branch from 0e2d679 to 5832b7c Compare March 6, 2017 22:01
Copy link
Contributor

@xymostech xymostech left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome.

@xymostech xymostech merged commit a7d2aff into Khan:master Mar 6, 2017
@lencioni lencioni deleted the runstringhandlers branch March 6, 2017 23:06
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.

2 participants