ID:2621745
 
Applies to:Dream Maker
Status: Open

Issue hasn't been assigned a status value.
I was thinking something along the lines of list.capacity = num to allow us to set the size of a user list's reserve capacity. (as well as read it). The idea mainly being to pre-load list capacity if we know a list will be large, as well as let us remove the reserve if we know the list will not receive anymore items.

If capacity is set to a number lower than len, it could either set it to len, throw a runtime, set len to it, or swallow the moon out of the sky, dev's choice, just be sure to document it.

additional reading: https://docs.microsoft.com/en-us/dotnet/api/ system.collections.generic.list-1.capacity?view=netcore-3.1

Bonus/alt ideas:

list.Compact(), resizes the underlying array to capacity. (for when you know it won't need to hold any more items)

list.auto_size = ENUM(AUTO | NO_SHRINK | NO_RESERVE). (manually setting capacity higher should automatically set NO_SHRINK, NO_RESERVE would only ever raise by 1, and auto shrink every time an item is removed.)

Making byond smarter about capacity: (byond may or may not be doing any or all of these, i wouldn't know)

Exact size compile time lists generated in init[].

Exact size all lists defined with list(...) until they get their first addition.

Exact size to the first usage of .len in any given tick, no reserve (but keep the normal reserve on later uses in the same world tick.) (this is not likely to be worth the memory needed to track the last usage of .len on the list)

Deallocate the entire array on .Cut() or len = 0 so the list has the same usage as a freshly created empty list.

Misc info:
A newly created empty list uses 24 bytes of memory, a list with zero items but used to have 1 item, uses 104 bytes. I was able to get this up to around ~300 bytes per empty list by adding just enough items in to it to get byond to upsize it, but not enough to get byond to shrink its capacity.
bump for 514 beta
Bump
I'll look at this for 515 and see what's feasible.

Lists do a lot of recycling so I'll need to think on this a bit.
This would make some key things much more efficient given work. Would love to see this happen
bump for 515
bump for 515
bump for 516