-
-
Notifications
You must be signed in to change notification settings - Fork 726
Description
The mangler benchmarks are extremely noisy, often reporting +/- 15% perf differences on PRs which don't touch the mangler at all. The mangler[cal.com.tsx] benchmark is the worst offender, but other mangler benchmarks are also displaying a lot of variance.
Presumably the source of this variance is unpredictable patterns of allocation.
The mangler already uses an Allocator internally for storing some temporary data. I suggest we try to put more of the temporary Vecs and HashMaps used in the mangler into this arena too. That should make the pattern of allocations more deterministic, and so reduce the variance in benchmarks. I would hope it may also be a performance gain, as it'll reduce allocations overall.
One note: When storing data in an arena, it becomes much more important to accurately predict upfront how large a Vec / HashMap is going to get, and reserve sufficient capacity when creating the Vec / HashMap.
Reserving sufficient capacity upfront is always a gain, because growing these structures is an expensive operation, especially if they're large. But when the Vec / HashMap is stored in an arena, it becomes even more important. When Vec / HashMap is stored on general heap, sometimes the OS can grow the allocation in place (very cheap), or resize it by altering the page table (somewhat cheap). But when the Vec / HashMap is in an arena, neither of these is an option, and growth always results in creating a new allocation and copying all the data from the old allocation to the new one (very expensive).