The goal here is to reduce excessive time spent growing slices and maps.
The idea would be to track slice/map declaration/allocation sites (by PC, perhaps including N frames of caller context for additional precision) and the typical (approximate median?) maximum size of containers from that allocation site. Future allocations would use the median to allocate the expected size up front, thus avoid grow work.
Some thoughts from initial discussions:
cc @cherrymui @mknyszek @aclements @hoeppi-google
The goal here is to reduce excessive time spent growing slices and maps.
The idea would be to track slice/map declaration/allocation sites (by PC, perhaps including N frames of caller context for additional precision) and the typical (approximate median?) maximum size of containers from that allocation site. Future allocations would use the median to allocate the expected size up front, thus avoid grow work.
Some thoughts from initial discussions:
Partially related to this: when growing, should we always align up to fill the entire size class. Leaving extra space in the size class is pure waste.-> already done: https://cs.opensource.google/go/go/+/master:src/runtime/slice.go;l=218;drc=d6ef98b8fa4851f025779ef4ade084d63290de2acc @cherrymui @mknyszek @aclements @hoeppi-google