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

Consider replacing List blocks with value types #20

Open
carmineos opened this issue Mar 2, 2021 · 2 comments
Open

Consider replacing List blocks with value types #20

carmineos opened this issue Mar 2, 2021 · 2 comments

Comments

@carmineos
Copy link
Owner

carmineos commented Mar 2, 2021

The list blocks should be replaced with value types, they are part of the structure data of the blocks which contain them, they are never referenced by another block, the actual references are the arrays the point at.
This will improve invoking GetParts which won't have to iterate on such "parts" and will drastically reduce number of allocations specially in resources like Particles.
They are all 16 bytes structs (pointer to array, count, capacity, padding).

The involved blocks are:

  • SimpleList64
  • ResourceSimpleList64
  • ResourceSimpleList32_64
  • ResourcePointerList64
@carmineos carmineos changed the title Consider replacing SimpleList/ResourceSimpleList with value types Consider replacing List blocks with value types Mar 2, 2021
@carmineos
Copy link
Owner Author

For instance these are the number of lists contained (as embedded parts) in core.ypt blocks:

RageLib.Resources.Common.SimpleList64`1[RageLib.Resources.GTA5.PC.Particles.Unknown_P_009]: 74541
RageLib.Resources.Common.ResourcePointerList64`1[RageLib.Resources.GTA5.PC.Particles.KeyframeProp]: 16533
RageLib.Resources.Common.ResourcePointerList64`1[RageLib.Resources.GTA5.PC.Particles.Behaviour]: 8310
RageLib.Resources.Common.ResourceSimpleList64`1[RageLib.Resources.GTA5.PC.Particles.Unknown_P_006]: 7225
RageLib.Resources.Common.ResourceSimpleList64`1[RageLib.Resources.GTA5.PC.Particles.EvolutionName]: 3278
RageLib.Resources.Common.ResourceSimpleList64`1[RageLib.Resources.GTA5.PC.Particles.Unknown_P_003]: 3278
RageLib.Resources.Common.ResourceSimpleList64`1[RageLib.Resources.GTA5.PC.Particles.Unknown_P_007]: 3278
RageLib.Resources.Common.ResourceSimpleList64`1[RageLib.Resources.GTA5.PC.Particles.Unknown_P_013]: 1662
RageLib.Resources.Common.ResourcePointerList64`1[RageLib.Resources.GTA5.PC.Particles.ShaderVar]: 1662
RageLib.Resources.Common.ResourceSimpleList64`1[RageLib.Resources.GTA5.PC.Particles.Unknown_P_012]: 1662
RageLib.Resources.Common.ResourcePointerList64`1[RageLib.Resources.GTA5.PC.Particles.EventEmitter]: 934
RageLib.Resources.Common.ResourcePointerList64`1[RageLib.Resources.GTA5.PC.Drawables.ShaderFX]: 46
RageLib.Resources.Common.ResourcePointerList64`1[RageLib.Resources.GTA5.PC.Drawables.DrawableGeometry]: 46
RageLib.Resources.Common.ResourcePointerList64`1[RageLib.Resources.GTA5.PC.Drawables.DrawableModel]: 46
RageLib.Resources.Common.SimpleList64`1[System.UInt32]: 5
RageLib.Resources.Common.ResourcePointerList64`1[RageLib.Resources.GTA5.PC.Textures.TextureDX11]: 1
RageLib.Resources.Common.ResourcePointerList64`1[RageLib.Resources.GTA5.PC.Drawables.Drawable]: 1
RageLib.Resources.Common.ResourcePointerList64`1[RageLib.Resources.GTA5.PC.Particles.ParticleRule]: 1
RageLib.Resources.Common.ResourcePointerList64`1[RageLib.Resources.GTA5.PC.Particles.EffectRule]: 1
RageLib.Resources.Common.ResourcePointerList64`1[RageLib.Resources.GTA5.PC.Particles.EmitterRule]: 1

@carmineos
Copy link
Owner Author

I've made a quick and dirty test at https://github.com/carmineos/gta-toolkit/tree/test/lists replacing just
RageLib.Resources.Common.SimpleList64`1[RageLib.Resources.GTA5.PC.Particles.Unknown_P_009]: 74541 with a struct holding the array header data.
When replacing list blocks with structs, the containing block will remove such list blocks from GetParts() and add the pointed array to GetReferences()

Before

|      Method | filename |  save |       Mean |    Error |   StdDev |      Gen 0 |      Gen 1 |     Gen 2 | Allocated |
|------------ |--------- |------ |-----------:|---------:|---------:|-----------:|-----------:|----------:|----------:|
| LoadSaveYpt | core.ypt | False |   733.4 ms |  6.37 ms |  5.96 ms | 20000.0000 |  9000.0000 | 3000.0000 | 226.48 MB |
| LoadSaveYpt | core.ypt |  True | 2,800.6 ms | 26.84 ms | 25.11 ms | 48000.0000 | 16000.0000 | 4000.0000 | 477.27 MB |

After

|      Method | filename |  save |       Mean |    Error |   StdDev |      Gen 0 |      Gen 1 |     Gen 2 | Allocated |
|------------ |--------- |------ |-----------:|---------:|---------:|-----------:|-----------:|----------:|----------:|
| LoadSaveYpt | core.ypt | False |   652.5 ms | 10.03 ms |  9.38 ms | 17000.0000 |  8000.0000 | 3000.0000 | 190.17 MB |
| LoadSaveYpt | core.ypt |  True | 2,652.2 ms | 34.90 ms | 30.94 ms | 39000.0000 | 14000.0000 | 3000.0000 | 422.07 MB |

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

No branches or pull requests

1 participant