Bug 133054 (TerrainPerf)

Summary: Performance testing, diamond-square terrain generation + canvas
Product: WebKit Reporter: Hunter Loftis <hunter>
Component: JavaScriptCoreAssignee: Geoffrey Garen <ggaren>
Status: RESOLVED FIXED    
Severity: Enhancement CC: commit-queue, ggaren, rniwa
Priority: P5    
Version: 528+ (Nightly build)   
Hardware: All   
OS: All   
URL: http://www.playfuljs.com/realistic-terrain-in-130-lines/
Bug Depends on: 133238    
Bug Blocks:    
Attachments:
Description Flags
Implementation of diamond-square terrain generation
none
Patch
none
Patch
none
Patch rniwa: review+

Description Hunter Loftis 2014-05-18 14:14:31 PDT
This is an implementation of the diamond-square terrain generation algorithm commonly used to generate fractal-noise worlds in games. It stores height map data in a Float32Array and renders to a fixed-sized canvas.

The benchmark averages the result of ten iterations.
Comment 1 Hunter Loftis 2014-05-18 14:15:11 PDT
Created attachment 231665 [details]
Implementation of diamond-square terrain generation
Comment 2 Geoffrey Garen 2014-05-22 11:47:41 PDT
Created attachment 231901 [details]
Patch
Comment 3 Geoffrey Garen 2014-05-22 11:48:16 PDT
Thanks, Hunter. 

I did a bit more formatting to bring this up to WebKit coding standards, and turned it into a patch that can apply to the source tree.
Comment 4 Ryosuke Niwa 2014-05-22 12:02:34 PDT
Comment on attachment 231901 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=231901&action=review

> PerformanceTests/Canvas/terrain.html:197
> +        benchmark(function() {
> +            var terrain = new Terrain(9);
> +            terrain.generate(0.5);
> +            ctx.clearRect(0, 0, width, height);
> +            terrain.draw(ctx, width, height);
> +        });

We should use PerfTestRunner.measureTime or reportValueAsync so that perf bots would be able to run this test.
Comment 5 Ryosuke Niwa 2014-05-22 12:03:17 PDT
Comment on attachment 231901 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=231901&action=review

> PerformanceTests/Canvas/terrain.html:41
> +        Math.random = (function() {
> +           var seed = 49734321;
> +           return function() {
> +               /* The Jenkins hash function:
> +                   <http://en.wikipedia.org/wiki/Jenkins_hash_function>
> +                   <http://burtleburtle.net/bob/hash/integer.html>
> +                */
> +               seed = ((seed + 0x7ed55d16) + (seed << 12)) & 0xffffffff;
> +               seed = ((seed ^ 0xc761c23c) ^ (seed >>> 19)) & 0xffffffff;
> +               seed = ((seed + 0x165667b1) + (seed << 5)) & 0xffffffff;
> +               seed = ((seed + 0xd3a2646c) ^ (seed << 9)) & 0xffffffff;
> +               seed = ((seed + 0xfd7046c5) + (seed << 3)) & 0xffffffff;
> +               seed = ((seed ^ 0xb55a4f09) ^ (seed >>> 16)) & 0xffffffff;
> +               return (seed & 0xfffffff) / 0x10000000;
> +           };
> +        })();

This is included in PerformanceTests/resources/runner.js
Comment 6 Ryosuke Niwa 2014-05-22 12:06:21 PDT
Comment on attachment 231901 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=231901&action=review

>> PerformanceTests/Canvas/terrain.html:197
>> +        });
> 
> We should use PerfTestRunner.measureTime or reportValueAsync so that perf bots would be able to run this test.

I think all you need to do is include ../resources/runner.js and then do:
PerfTestRunner.measureTime({run: function () {
    var terrain = new Terrain(9);
    ...
}})
Comment 7 Geoffrey Garen 2014-05-23 15:00:23 PDT
Created attachment 231994 [details]
Patch
Comment 8 Geoffrey Garen 2014-05-23 15:12:20 PDT
Created attachment 231995 [details]
Patch
Comment 9 Geoffrey Garen 2014-05-23 15:37:55 PDT
Committed r169287: <http://trac.webkit.org/changeset/169287>