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

Improved getNavigationLink Performance #95

Merged
merged 7 commits into from
Oct 10, 2016
Merged

Improved getNavigationLink Performance #95

merged 7 commits into from
Oct 10, 2016

Conversation

grahammendick
Copy link
Owner

@grahammendick grahammendick commented Oct 10, 2016

Doubled the speed of getNavigationLink. Reduced the time to produce 10,000 links from 80ms to 40ms.

var stateNavigator = new Navigation.StateNavigator([
    {key: 'ab', route: 'a/{a}/b/{b}', defaultTypes: {b: 'number'}}
]);

function run(){
  for(var i = 0; i < 10000; i++){
    stateNavigator.getNavigationLink('ab', { a: 'abc', b: 123 });
  }
}

Made two changes in NavigationDataManager, each responsible for a 30% speed increase:

  • Replaced new RegExp('_', 'g') with /_/g
  • Replaced Object.prototype.toString.call with typeof

Improved getNavigationLink by about 30%
Object toString is slower than typeof,
http://stackoverflow.com/a/11231664/1310468. Trouble is typeof doesn't
work for Date or Array because it returns "obejct". So, used typeof
first and fell back on toString. For strings, numbers and booleans
(majority of cases) speed improved by about 30%
Matches performance change to NavigationDataManager. Less important here
because only applies to arrays but still relevant and makes code
consistent
These were hangovers from when Route was part of public Api
@grahammendick grahammendick merged commit 81bff39 into master Oct 10, 2016
@grahammendick grahammendick deleted the performance branch October 10, 2016 14:37
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.

1 participant