Skip to content
This repository was archived by the owner on Jul 29, 2019. It is now read-only.

Conversation

@rgriffogoes
Copy link
Contributor

Adding some caching (a better name would be memoization) to Range.prototype.getMillisecondsPerPixel.

In my case, this function was responsible for quite some time (see attached chrome profiling), and from what I could understand, I could cache the results quite easily (as the results only changes after a "setRange").

Some bench marking, while adding some points to the timeline:

#items	4.20.1-snapshot		withCache
500	5.147s			2.844s
1000	19.879s			11.635s
2000	76.248s			48.438s

We can see some clear improvements (and the quadratic behavior!)

getmillisecondsperpixel

*/
Range.prototype.getMillisecondsPerPixel = function() {
return (this.end - this.start) / this.body.dom.center.clientWidth;
if (this.millisecondsPerPixelCache === undefined) {
Copy link
Member

Choose a reason for hiding this comment

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

It would be cleaner if it would be:

if (!this.millisecondsPerPixelCache) { ... }
return this.millisecondsPerPixelCache

@yotamberk
Copy link
Member

I like this very much, so i'll accept it!

@yotamberk yotamberk merged commit 56083ec into visjs:develop Jun 13, 2017
yotamberk added a commit to yotamberk/vis that referenced this pull request Jul 2, 2017
move - FEAT visjs#3154 to timeline
yotamberk added a commit that referenced this pull request Jul 2, 2017
* Fix redraw order

* Fix error when option is not defined

* Allow template labels

* Add .travis.yml file

* Add experiment travis code

* Fix react example

* created a checklist for the release process

* unchecked everything

* added make github release

* Remove npm-debug logs

* Release v4.20.1

* Update HISTORY.md

Fix indents

* Update HISTORY.md

* Update HISTORY.md

move - FEAT #3154 to timeline
primozs pushed a commit to primozs/vis that referenced this pull request Jan 3, 2019
primozs pushed a commit to primozs/vis that referenced this pull request Jan 3, 2019
* Fix redraw order

* Fix error when option is not defined

* Allow template labels

* Add .travis.yml file

* Add experiment travis code

* Fix react example

* created a checklist for the release process

* unchecked everything

* added make github release

* Remove npm-debug logs

* Release v4.20.1

* Update HISTORY.md

Fix indents

* Update HISTORY.md

* Update HISTORY.md

move - FEAT visjs#3154 to timeline
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants