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 performance of translateToContainerFullname function #111

Merged
merged 1 commit into from
Aug 28, 2015

Conversation

joshvfleming
Copy link

While CPU profiling our app, we noticed that the
translateToContainerFullname function was taking quite a lot of time,
and this seemed to be mostly on account of regex use. This commit replaces
the regexes with equivalent string manipulation logic. The
translateToContainerFullname disappeared from the offenders list in our
CPU profiles after the change.

Before:

translatetocontainerfullname-fix-before

After:

translatetocontainerfullname-fix-after

@stefanpenner
Copy link
Contributor

@joshvfleming good catch. I guess ED was having some fun translating :P (at one point this method was rarely used)

I am glad to see an implementation change improved the speed without the need for a cach

@stefanpenner
Copy link
Contributor

@joshvfleming looks like some failing tests yet, otherwise it appears like a great addition.

@rwjblue
Copy link
Member

rwjblue commented Aug 28, 2015

Looks like failing tests have to do with bad test setup (returning something as a route that isn't stamped with isRouteFactory) and changes on Ember canary.

@stefanpenner
Copy link
Contributor

@joshvfleming also curious:

  • which version of ember
  • which version of data
  • is this a prod build

@stefanpenner
Copy link
Contributor

actually a quick look, indicates we likely really shouldn't be calling this method that many times.

knownForType: function(type) {

Although it is great to make it faster and we should merge this when green, calling it so many times is potentially related to a larger underlying issue. And i wouldn't be surprised if improving the calling side wouldn't have other positive side-affects.

Can you share the callstack of its invocation ? Likely expanding its entry in the profile would be sufficient.

@rwjblue
Copy link
Member

rwjblue commented Aug 28, 2015

knownForType should be called once for initial render of each test.

@joshvfleming
Copy link
Author

Ember canary 987a593 (also latest canary, just checked)
Ember-data canary 9a85784 (same)
Prod build
Another potentially relevant data point: this is running in fastboot mode in Node, v 0.12.7

This is the stack I'm seeing:

screen shot 2015-08-28 at 5 32 29 pm

It does seem to be a small number of really slow calls rather than an aggregation of a large number calls.

Also, I believe the test failures are unrelated to this commit -- the tests fail the same way for me with the previous commit.

@stefanpenner
Copy link
Contributor

Also, I believe the test failures are unrelated to this commit -- the tests fail the same way for me with the previous commit.

ya, @rwjblue mentioned it was an issue with latest canary.

It does seem to be a small number of really slow calls rather than an aggregation of a large number calls.

interesting, so this must mean a large number of internal modules (thousands)

Can you share the number of calls 10s 100s etc.

Clearly the biggest cost was constantly creating new regexp.

@stefanpenner
Copy link
Contributor

@rwjblue you seem to have a clear grasp on the test failure. Do you have time to look, or share the steps?

I would love to release a new version of the resolver shortly including @joshvfleming's work.

@stefanpenner
Copy link
Contributor

@rwjblue another approach, to mitigate the need for this at all. Is to do this at compilation time, and providing some module meta-data pre-constructed. Although inlight of this PR's improvement, likely not worth it yet.

@rwjblue
Copy link
Member

rwjblue commented Aug 28, 2015

Ya, I will PR fixing the test failure to master so we can focus on this separately.

@stefanpenner
Copy link
Contributor

Ya, I will PR fixing the test failure to master so we can focus on this separately.
Hide all checks

thanks

@rwjblue
Copy link
Member

rwjblue commented Aug 28, 2015

#112 should fix master

@stefanpenner
Copy link
Contributor

@joshvfleming can we get a quick rebase ?

While CPU profiling our app, we noticed that the
translateToContainerFullname function was taking quite a lot of time,
and this seemed to be mostly on account of regex use. This commit replaces
the regexes with equivalent string manipulation logic. The
translateToContainerFullname disappeared from the offenders list in our
CPU profiles after the change.
@joshvfleming
Copy link
Author

@stefanpenner Just rebased and pushed. Regarding the call counts, I'll need to grab that from my work laptop on Monday.

Thanks @stefanpenner and @rwjblue for looking into this so quickly!

stefanpenner added a commit that referenced this pull request Aug 28, 2015
Improve performance of translateToContainerFullname function
@stefanpenner stefanpenner merged commit 422e07c into ember-cli:master Aug 28, 2015
@stefanpenner
Copy link
Contributor

released as v0.1.21

@rwjblue
Copy link
Member

rwjblue commented Aug 28, 2015

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.

3 participants