Join GitHub today
GitHub is home to over 36 million developers working together to host and review code, manage projects, and build software together.
Sign upSwap out item vector for a std::list. #9917
Comments
kevingranade
added
<Enhancement / Feature>
Code: Performance
labels
Nov 9, 2014
This comment has been minimized.
This comment has been minimized.
|
It's even worse when waiting:
It looks like the only real candidate for why this is taking so long is vector insertion and removal. The higher-level solution is to split off some active items to something resembling timer queues, e.g. you'd evenly distribute all the rotting food across n containers, and only process one containers worth per turn. More detail in #9926 |
This comment has been minimized.
This comment has been minimized.
|
I'm a dumb, there's no reason for the items to be sorted, just put them in a std::list and either append or prepend. (prepend is better actually, then you can just iterate to the end of the list) |
This comment has been minimized.
This comment has been minimized.
|
If std:list is way to go, can you please change the label to 'Swap out item vector for a std::list' ? |
kevingranade
changed the title
Swap out item vector for a std::map.
Swap out item vector for a std::list.
Nov 10, 2014
This comment has been minimized.
This comment has been minimized.
|
Yea, I was going to do that but was having terrible connection issues to github last night, so gave up. |
kevingranade commentedNov 9, 2014
While profiling for pre-0.B stuff, I noticed that we're spending a significant amount of time inserting and removing items from the item vector:
It's probably going to take quite a bit of doing, but I think switching the items std::vector to a std::map is the right way to go. It has the best insertion/removal performance, and we almost always iterate over the container rather than random access elements.