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

Better performance for large Tilesets #125

Merged
merged 3 commits into from
Jun 3, 2023
Merged

Conversation

mateusvmv
Copy link
Contributor

This creates an index of tiles by their ID, removing the need for a sort in the vector of tiles. It also makes getTile() and createMissingTile() constant operations.

@fallahn
Copy link
Owner

fallahn commented Jun 2, 2023

Thanks for the contribution! I'll review this as soon as I get a moment.

@pedro-w
Copy link

pedro-w commented Jun 2, 2023

Have you any idea how much faster it is, or is there any trade-off for small tilesets?

@mateusvmv
Copy link
Contributor Author

Old version

2023-06-02T12:51:45-03:00
Running target/main
Run on (8 X 4700 MHz CPU s)
CPU Caches:
  L1 Data 48 KiB (x4)
  L1 Instruction 32 KiB (x4)
  L2 Unified 1280 KiB (x4)
  L3 Unified 12288 KiB (x1)
Load Average: 0.98, 1.02, 0.81
***WARNING*** CPU scaling is enabled, the benchmark real time measurements may be noisy and will incur extra overhead.
---------------------------------------------------------
Benchmark               Time             CPU   Iterations
---------------------------------------------------------
load_64            176208 ns       175691 ns         3828
load_256           919361 ns       917782 ns          748
load_1024         6971374 ns      6964565 ns           99
load_4096        80409813 ns     80355550 ns            9
load_16384     1159271843 ns   1158359383 ns            1
load_terrain   1241114701 ns   1239296687 ns            1
access_64             385 ns          384 ns      1795010
access_256           1033 ns         1031 ns       683887
access_1024          3620 ns         3617 ns       194972
access_4096         14227 ns        14213 ns        50738
access_16384        54770 ns        54740 ns        13114
access_terrain      53067 ns        53033 ns        13454

New version

2023-06-02T12:50:52-03:00
Running target/main
Run on (8 X 4700 MHz CPU s)
CPU Caches:
  L1 Data 48 KiB (x4)
  L1 Instruction 32 KiB (x4)
  L2 Unified 1280 KiB (x4)
  L3 Unified 12288 KiB (x1)
Load Average: 0.77, 1.00, 0.79
***WARNING*** CPU scaling is enabled, the benchmark real time measurements may be noisy and will incur extra overhead.
---------------------------------------------------------
Benchmark               Time             CPU   Iterations
---------------------------------------------------------
load_64             44049 ns        43591 ns        16714
load_256           144376 ns       143824 ns         4911
load_1024          435758 ns       435321 ns         1553
load_4096         1739058 ns      1737042 ns          404
load_16384        7071796 ns      7062606 ns          101
load_terrain     16020146 ns     16002824 ns           43
access_64            27.2 ns         27.2 ns     25666550
access_256           27.3 ns         27.3 ns     24344543
access_1024          27.5 ns         27.5 ns     25592641
access_4096          27.3 ns         27.2 ns     25466592
access_16384         27.4 ns         27.4 ns     25624132
access_terrain       27.4 ns         27.4 ns     25508625

The load functions are loading tilemaps with that amount of tiles.
The access functions are calling getTile with a random tile id.
The tilemap files are of the format:

<?xml version="1.0" encoding="UTF-8"?>
<map version="1.10" tiledversion="1.10.1" orientation="orthogonal" renderorder="right-down" width="256" height="256" tilewidth="32" tileheight="32" infinite="0">
 <tileset firstgid="1" source="4096.tsx"/>
</map>

And the tileset files are of the format:

<?xml version="1.0" encoding="UTF-8"?>
<tileset version="1.10" tiledversion="1.10.1" name="phony" tilewidth="32" tileheight="32" tilecount="4096" columns="1">
 <image source="phony.png" width="2048" height="2048"/>
</tileset>

Terrain is the preview map of lpc terrains

@fallahn
Copy link
Owner

fallahn commented Jun 2, 2023

Wow! That's a considerable speed up - nice work! 😁

@fallahn fallahn merged commit 6341835 into fallahn:master Jun 3, 2023
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.

3 participants