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

Cr/issue 138 #139

Merged
merged 3 commits into from
Aug 25, 2016
Merged

Cr/issue 138 #139

merged 3 commits into from
Aug 25, 2016

Conversation

carlos8f
Copy link
Contributor

fixes issue #138

@andredumas
Copy link
Owner

hmmm. jsperf been down for a while. Makes cross browser profiling and sharing results a bit difficult. Have some results to share, will probably create a few gists.

@@ -34,7 +34,7 @@ module.exports = function(d3_scale_linear, d3_time, d3_bisect, techan_util_rebin
* @returns {*}
*/
function scale(x, offset) {
var mappedIndex = dateIndexMap[+x];
var mappedIndex = dateIndexMap[x.getTime ? x.getTime() : +x];
Copy link
Owner

Choose a reason for hiding this comment

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

Nice catch here, but after profiling I would prefer:

x instanceof Date ? x.getTime() : +x

Faster still (for me, linux chrome) and handles undefined and nulls gracefully (without error). I'll add some test cases around the nulls and undefines.

Copy link
Owner

Choose a reason for hiding this comment

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

@andredumas
Copy link
Owner

Profile tests: https://gist.github.com/andredumas/7a3277e3cb06c35f4ba34562a873cf35

Thanks for picking this up. As a result will be migrating all the Array.joins across to static or string concat instead.

@andredumas andredumas added this to the 0.7.0 milestone Aug 22, 2016
@carlos8f
Copy link
Contributor Author

The instanceof version isn't displaying in my chrome profile result, so i'm not sure if it's faster or slower than duck typing.

screen shot 2016-08-21 at 6 46 54 pm

Any reason for String constructor rather than implicit conversion?

Just because I hate that js uses + when that should be reserved for math, and weird things can happen when you mix math with concat... if implicit is faster though, I'm for it.

@carlos8f
Copy link
Contributor Author

static concat dramatically wins, this is good 👍

screen shot 2016-08-21 at 6 53 15 pm

@andredumas
Copy link
Owner

Interesting, for me instanceof is almost at the bottom. It doesn't always appear when running in incognito though. I'm guessing extensions bootstrapping maybe slowing the run down allowing profiler to get a sample vs not in incognito as the browser seems to be doing a lot more.

The difference is so huge, I almost think there's something wrong with the test...

perf1

perf3

@andredumas
Copy link
Owner

implicit conversion sometimes doesn't appear, still not sure exactly what that means, but when it does it is further down the list. I've also randomised inputs for both date instance and number to string tests, results similar.
perf4

Agree it's not much fun reading those statements, and I'm no performance expert, but it would appear some carefully placed parenthesis and static concat is a winner here. For chrome anyway.

I'll make a few mods in techan locally and run the profile again. I'm keen to make crosshairs as responsive as possible and will use the same for other interactions.

@andredumas andredumas merged commit d8eefca into andredumas:master Aug 25, 2016
@andredumas
Copy link
Owner

Thanks for the contribution @carlos8f

andredumas added a commit that referenced this pull request Aug 25, 2016
…string constructor removal, remove Array.join

* Adding financetime tests to ensure scale of null and undefined are handled gracefully
* Removing String constructor, profiling appears quicker without
* Removing usage of Array.join. Array.join is very slow in chrome
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