carmineos / rage-toolkit

Other
19 stars 6 forks source link

Replace small resource blocks with structs #21

Closed carmineos closed 3 years ago

carmineos commented 3 years ago

Closes https://github.com/carmineos/gta-toolkit/issues/17

Some small structs which only happen to be packed into arrays can be replaced with structs. Such structs have to implement the new IResourceStruct<T> interface which for now only ensures contains a method allowing to return a copy of the instance in which all the fields have their endianness reversed. This covers blocks from Bounds, Nodes, Navigation.

Both loading and saving of such resources get great benefits from this change in both speed and allocated managed memory.

Before:

|      Method |             filename |  save |           Mean |        Error |       StdDev |      Gen 0 |      Gen 1 |     Gen 2 |    Allocated |
|------------ |--------------------- |------ |---------------:|-------------:|-------------:|-----------:|-----------:|----------:|-------------:|
| LoadSaveYbn |  cs6_08_mine_int.ybn | False |   290,886.0 us |  5,784.90 us |  8,479.43 us | 11000.0000 |  5000.0000 | 2000.0000 |  80738.54 KB |
| LoadSaveYbn |  cs6_08_mine_int.ybn |  True |   559,022.4 us |  8,641.19 us |  7,215.78 us | 20000.0000 | 10000.0000 | 4000.0000 | 114639.11 KB |
| LoadSaveYnv | navme(...)].ynv [21] | False |     7,209.3 us |     94.76 us |     88.64 us |   500.0000 |   250.0000 |  250.0000 |   3518.87 KB |
| LoadSaveYnv | navme(...)].ynv [21] |  True |    15,771.8 us |    298.52 us |    319.41 us |   828.1250 |   484.3750 |  296.8750 |   4990.52 KB |
| LoadSaveYnd |         nodes300.ynd | False |       380.3 us |      5.72 us |      5.35 us |    13.1836 |          - |         - |     54.98 KB |
| LoadSaveYnd |         nodes300.ynd |  True |       962.2 us |     19.16 us |     21.29 us |    21.4844 |     1.9531 |         - |     88.56 KB |

After:

|      Method |             filename |  save |           Mean |        Error |       StdDev |      Gen 0 |      Gen 1 |     Gen 2 |    Allocated |
|------------ |--------------------- |------ |---------------:|-------------:|-------------:|-----------:|-----------:|----------:|-------------:|
| LoadSaveYbn |  cs6_08_mine_int.ybn | False |    27,164.6 μs |     91.88 μs |     71.74 μs |  1375.0000 |  1000.0000 |  656.2500 |    8644.7 KB |
| LoadSaveYbn |  cs6_08_mine_int.ybn |  True |   174,738.4 μs |  1,121.60 μs |    994.27 μs |  1666.6667 |  1333.3333 | 1000.0000 |   13074.7 KB |
| LoadSaveYnv | navme(...)].ynv [21] | False |     1,087.3 μs |     21.60 μs |     26.53 μs |    44.9219 |    44.9219 |   44.9219 |    306.31 KB |
| LoadSaveYnv | navme(...)].ynv [21] |  True |     5,819.6 μs |     77.73 μs |     72.71 μs |    85.9375 |    85.9375 |   85.9375 |    485.53 KB |
| LoadSaveYnd |         nodes300.ynd | False |       289.6 μs |      5.38 μs |      5.28 μs |     4.3945 |          - |         - |     19.63 KB |
| LoadSaveYnd |         nodes300.ynd |  True |       831.9 μs |      7.84 μs |      6.95 μs |     8.7891 |          - |         - |     38.03 KB |