Skip to content

Cache Voronoi source points.#4

Open
player-03 wants to merge 3 commits intomemilian:masterfrom
player-03:cache
Open

Cache Voronoi source points.#4
player-03 wants to merge 3 commits intomemilian:masterfrom
player-03:cache

Conversation

@player-03
Copy link
Copy Markdown

@player-03 player-03 commented Mar 16, 2022

This requires some input from the user but seriously improves performance. Basically it looks like this:

var module = new Voronoi(0.02, 1, 234, false);
module.cache(0, 0, 0, 100, 100, 100);

// The cached area is faster to calculate:
module.getValue(10, 20, 30);
module.getValue(50, 50, 50);
module.getValue(100, 0, 100);
module.getValue(40, 50, 60);

// You can still get values outside the area, but they aren't faster:
module.getValue(200, 0, 0);
module.getValue(-1, -1, -1);

Tested primarily in HashLink and HTML5. In HashLink it shaves off about 33% of the time required, while in HTML5 it shaves off about 66%.

Requires some input from the user, but seriously improves performance.

It might be possible to improve performance further using `Bytes`.
@player-03
Copy link
Copy Markdown
Author

The currently-submitted version is the best I could come up with, but I also tried some alternatives. For the record:

  • I tried storing data in one big haxe.io.Bytes object, and while this helped a little in JavaScript, it noticeably hurt C++, HashLink, and Neko. (Maybe a 33% slowdown? I forget exactly.)
  • I tried Array<Array<Array<Float>>> (with the innermost array storing 3x as many Floats) instead of Array<Array<Array<Site>>> (where Site is a class with three Float variables), with the same results.
  • It feels like iteration order (x→y→z vs. z→y→x) should matter for cache misses, but I tried it and it seemed to make no difference.
  • Optional arguments are incredibly slow in C++, HashLink, and Neko. By which I mean they're comparable to two calls to Utils.ValueNoise3D. So instead of the cache speeding things up by 33%, it slowed everything down by 100%.

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