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 all 'Array.forEach' with 'for of' cycle #1423

Merged
merged 1 commit into from
Jul 17, 2018

Conversation

IvanGoncharov
Copy link
Member

Is there a concrete reason to make this change? .forEach is how most things are done in this library, and I'd prefer to maintain consistency.

@mjmahone for of is 4x faster than forEach + arrow function: https://jsperf.com/for-of-vs-foreach5
If we enable loose mode for for of than it will be 12x speedup.
Also, for of don't force us to create closures so it should lower memory usage in recursive functions.

But more importantly, the main purpose of this library is to be the reference implementation of GraphQL so code readability is very important.

Copy link
Contributor

@mjmahone mjmahone left a comment

Choose a reason for hiding this comment

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

I personally disagree with for of being more readable, but I come from a very functional-language background. The performance benefit though is tangible and significant enough that I'm on board!

@mjmahone mjmahone merged commit e6c36e0 into graphql:master Jul 17, 2018
@IvanGoncharov IvanGoncharov deleted the forEachRewrite branch July 18, 2018 15:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants