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

perf: Improve performance of toTitleCase, register with lower and tit… #6148

Merged
merged 3 commits into from
Aug 7, 2019

Conversation

brandonocasey
Copy link
Contributor

ToTileCase is one of our biggest startup functions, taking about 12ms to run. This pull request speeds that up by:

  1. Making the toTitleCase function faster
  2. Adding a toLowerCase function so that we can register title and lower case tech names
  3. Since we register both title and lower case tech names, we can omit toTitleCase in most common scenarios

with all this done toTitleCase + toLowerCase take about 0.6ms combined!

@brandonocasey brandonocasey changed the title perf: Imporve performance of toTitleCase, register with lower and tit… perf: Improve performance of toTitleCase, register with lower and tit… Jul 31, 2019
Copy link
Member

@gkatsev gkatsev left a comment

Choose a reason for hiding this comment

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

Do we need any additional tests for getChild/registerComponent?

src/js/utils/to-lower-case.js Outdated Show resolved Hide resolved
src/js/utils/to-lower-case.js Outdated Show resolved Hide resolved
@@ -358,8 +359,6 @@ class Component {
return;
}

name = toTitleCase(name);
Copy link
Member

Choose a reason for hiding this comment

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

so, basically, this is the big gain here? Because we register the component both as component and as Component, we can just assume it'll be available and we don't need to toTitleCase the name?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

exactly!

@@ -432,7 +431,8 @@ class Component {
componentName = componentName || (component.name && toTitleCase(component.name()));

if (componentName) {
this.childNameIndex_[componentName] = component;
this.childNameIndex_[toTitleCase(componentName)] = component;
Copy link
Member

Choose a reason for hiding this comment

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

Is this needed? The behavior related to this isn't changing. Same with line 484.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We need this because, getChild used to toTitleCase the name that it was given. Now we won't do that because we register both possible names during addChild.

Copy link
Member

Choose a reason for hiding this comment

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

oh, didn't realize that getChild used this property. However, it sounds like we don't need to call toTitleCase again because it sounds like componentName is always toTitleCased per lines 430 and 388. So, we would only need to register the toLowerCase version.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

@gkatsev gkatsev merged commit 266cb15 into master Aug 7, 2019
@gkatsev gkatsev deleted the perf/to-title-case branch August 7, 2019 20:05
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.

2 participants