Skip to content

Pack Vehicle and StreamInVehicle more tightly#1091

Merged
AmyrAhmady merged 1 commit into
openmultiplayer:masterfrom
PTemuri:vehicle_size_optimization
May 21, 2025
Merged

Pack Vehicle and StreamInVehicle more tightly#1091
AmyrAhmady merged 1 commit into
openmultiplayer:masterfrom
PTemuri:vehicle_size_optimization

Conversation

@PTemuri

@PTemuri PTemuri commented May 21, 2025

Copy link
Copy Markdown
Contributor

Minor size optimizations
Pack Vehicle and StreamInVehicle more tightly
Size decrease: for Vehicle from 480 bytes to 464 bytes, for StreamInVehicle from 116 bytes to 108 bytes
May be useful for future development, to avoid crossing alignment boundary
No functional changes whatsover

Vehicle from 480 bytes to 464 bytes, StreamInVehicle from 116 bytes to 108 bytes
@AmyrAhmady AmyrAhmady merged commit 8f3a310 into openmultiplayer:master May 21, 2025
@xgreatxfortunex333

Copy link
Copy Markdown

@AmyrAhmady
image
What even is this PR

@AmyrAhmady

AmyrAhmady commented Jun 24, 2025

Copy link
Copy Markdown
Member

It's packing the structures so we don't waste memory due to assigned paddings during allocations.
It is also good for data locality and caching as well

@xgreatxfortunex333

xgreatxfortunex333 commented Jul 4, 2025

Copy link
Copy Markdown

Minor size optimizations
Pack Vehicle and StreamInVehicle more tightly
Size decrease: for Vehicle from 480 bytes to 464 bytes, for StreamInVehicle from 116 bytes to 108 bytes
May be useful for future development, to avoid crossing alignment boundary
No functional changes whatsover

so saving (at max vehicles) 0.032 megabytes matters now?

I got the cache part but memory cmon

@AmyrAhmady

Copy link
Copy Markdown
Member

It isn't about only those two structure members. All of them are done like and those two weren't following.
Just because the size is small it doesn't mean we should leave it like and not follow how it has been done literally everywhere for other members, to have proper alignment.

Also I said "during allocation", maybe I wasn't clear enough. more space to allocate (even small) = less impact on performance
Specially with objects that are allocated very frequently.

But the whole idea of this PR was to fix something that is done everywhere and it was missing for those two members. I we didn't care about it and all the other members had byte paddings then the size difference wouldn't have been that small for you to nitpick it

@xgreatxfortunex333

Copy link
Copy Markdown

It isn't about only those two structure members. All of them are done like and those two weren't following. Just because the size is small it doesn't mean we should leave it like and not follow how it has been done literally everywhere for other members, to have proper alignment.

Also I said "during allocation", maybe I wasn't clear enough. more space to allocate (even small) = less impact on performance Specially with objects that are allocated very frequently.

But the whole idea of this PR was to fix something that is done everywhere and it was missing for those two members. I we didn't care about it and all the other members had byte paddings then the size difference wouldn't have been that small for you to nitpick it

I just asked, because usually on the official discord server people would burn you alive if you talked about megabytes of memory in your script yet here 32kb was a concern, sorry~~

@AmyrAhmady

Copy link
Copy Markdown
Member

It's fine
As I said, it's more like following a rule so we make sure it's the same everywhere in every structure
it's not noticeably for exact changes in this PR, but it's definitely noticeable when every structure tries to follow this rule

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