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

Use an autogrowing vector instead of an array for Station::goods #3694

Closed
DorpsGek opened this issue Mar 14, 2010 · 2 comments
Closed

Use an autogrowing vector instead of an array for Station::goods #3694

DorpsGek opened this issue Mar 14, 2010 · 2 comments
Labels
flyspray This issue is imported from FlySpray (https://bugs.openttd.org/) patch from FlySpray This issue is in fact a Patch, but imported from FlySrpay

Comments

@DorpsGek
Copy link
Member

fonsinchen opened the ticket and wrote:

At the moment Station::goods is a static array of size 32. There is a lot of code iterating over that array. However most stations only have a few active goods and the most used cargos have IDs < 12 as those are the stock cargos. This means the space required for keeping all the goods in memory as well as the time required to iterate over them can be reduced by providing a better container.

This patch provides an autogrowing vector. On operator[] it will do a length check and add further entries if it's too small. If you iterate over the vector using its iterator the length check is not done and of course it stops at the last entry that has been added with operator[]. The code using the goods entries has been altered to use the iterator where possible.

The run time performance increase caused by this change is hard to measure as there is no central place where it can be seen. However, simple comparisons of runtime for a fixed number of ticks (-v null:ticks=100000) with various save games suggest a speedup of roughly 0.8%. On my computer the size of a GoodsEntry is 32 bytes. thus cutting an average of 20 (= 32-12) GoodsEntries from each station reduces memory consumption by 640 bytes per station. For 100 stations that's 62.5k which might be noticable on small systems. 20 is a low estimate, as a lot of stations don't use cargo 11 (food, if it's a stock cargo). However, the std::vector also adds 3 pointers to each station at a cost of 4 or 8 bytes each.

Attachments

Reported version: trunk
Operating system: All


This issue was imported from FlySpray: https://bugs.openttd.org/task/3694
@DorpsGek
Copy link
Member Author

fonsinchen wrote:

I think we can drop this. I'm not maintaining the patch anymore as I think the performance increase is not worth the hassle of maintaining the patch. I still think that there is potential for improvement in this area but maybe someone comes up with a simpler idea.


This comment was imported from FlySpray: https://bugs.openttd.org/task/3694#comment8133

@DorpsGek
Copy link
Member Author

andythenorth closed the ticket.

Reason for closing: Requested by user

Fonso suggests this isn't relevant any more. Closing, thanks.


This comment was imported from FlySpray: https://bugs.openttd.org/task/3694

@DorpsGek DorpsGek added Core flyspray This issue is imported from FlySpray (https://bugs.openttd.org/) patch from FlySpray This issue is in fact a Patch, but imported from FlySrpay labels Apr 7, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flyspray This issue is imported from FlySpray (https://bugs.openttd.org/) patch from FlySpray This issue is in fact a Patch, but imported from FlySrpay
Projects
None yet
Development

No branches or pull requests

1 participant