Gigoteur / UnicornConsole

Unicorn Console: create quick fantasy game in Rust/Python/Lua/Rhai/Wasm !
MIT License
908 stars 47 forks source link

Faster, faster! #44

Closed johnbatty closed 7 years ago

johnbatty commented 7 years ago

Performance improvements, focussing on putpixel performance. Plus a few small bonus fixes.

Before/after performance results, showing 4x - 20x improvement :-)

[before]
test                iterations          total_time(secs)    time_per_op(us)
cls                  1000000               6.892               6.892
small_rect           1000000               3.588               3.588
small_rectfill       1000000               9.083               9.083
large_rect            100000               2.728              27.284
large_rectfill         10000               8.283             828.340
text                  100000               1.569              15.695
line                  100000               0.795               7.955
circ                  100000               1.398              13.979
circfill               10000               2.533             253.344

[after]
test                iterations          total_time(secs)    time_per_op(us)
cls                  1000000               0.518               0.518
small_rect           1000000               1.470               1.470
small_rectfill       1000000               1.645               1.645
large_rect            100000               0.256               2.561
large_rectfill         10000               0.397              39.729
text                  100000               0.381               3.812
line                  100000               0.179               1.791
circ                  100000               0.225               2.251
circfill               10000               0.139              13.866

I also added some detailed rendering performance measurements, as I added the new screen buffer to RGB translation there. This showed the RGB conversion step (the first measurement below) to be minimal (about 50us per frame). I left these measurements in the code - they can be enabled/displayed using a new "blit_perf" feature (disabled by default).

Render performance
gen_rgb:PT0.000063756S update_tex:PT0.000233939S copy_tex:PT0.003474850S present:PT0.002301755S
gen_rgb:PT0.000047360S update_tex:PT0.000262126S copy_tex:PT0.000026018S present:PT0.015566266S
gen_rgb:PT0.000048056S update_tex:PT0.000292806S copy_tex:PT0.000110042S present:PT0.014779848S
gen_rgb:PT0.000046136S update_tex:PT0.000260689S copy_tex:PT0.000025983S present:PT0.015485252S

I've tested with the demos and games, found and fixed a few issues. Currently have no known issues with the changes.

hallucino commented 7 years ago

Awesome !! The improvement is really huge !

Thanks

hallucino commented 7 years ago

I did some tests on raspberry pi and it works really correctly

hallucino commented 7 years ago

I added some checks that you removed because I got some crashes: https://github.com/Gigoteur/PX8/commit/7f34f5859c0cd111f2baa52b528aa52d5cbca43d

hallucino commented 7 years ago

I think the impact is not really huge (for my modification_