You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Large compile-time-memory-usage regression with regalloc2 #4291
I did some investigation on this yesterday and today (not quite fulltime, I'm still under the weather a bit, but regalloc hacking is still the best way to pass the time...). I found three distinct things I could improve:
Most importantly, some ugly quadratic behavior with liverange splitting. The heuristic has always been "split at first conflict", and a split is always a 2-for-1 deal, not N-for-1. The test program above has a single vreg that is passed as arg0, then arg1, then arg0, then arg1, ... through a long sequence of callsites. This means that it has to be split into N pieces each of which can be put in the appropriate register. Unfortunately splitting had cost O(|bundle|), i.e. proportional to the total length of the bundle. Bad news! My fix to this issue is to "bottom out" at a limit: if a single original bundle is split more than K times (10, for now), go ahead and do an N-for-1 split into minimal pieces.
Also, during splitting, we were copying the Use list over to the new second half, and truncating in the first, but not shrink_to_fit'ing. So we had O(n^2) memory at the end of the run too. D'oh.
Finally, handling of call-ABI clobbers had a bit too much overhead by treating them as normal defs; I went ahead and resolved an old TODO and used the proper clobbers API, and also adopted a bitmask-based clobbers representation rather than a list. On the Cranelift side the clobbers-list is now a const bitmask for an ABI rather than a dynamically-built thing with allocations and all the rest.
This moved the needle on compilation of the above significantly:
So v0.36 is ever-so-slightly faster (by ~5%) but curiously the current main-with-fixes runs ~5% fewer instructions during compilation, just gets a lower IPC. Fewer pagefaults ( == less memory) in current as well. These numbers are close enough to "within noise" I'd want to measure more carefully before making strong claims here. I do feel comfortable saying "anomaly fixed and back to parity" though, given the above.
I suspect this may be the same issue we saw in #4045 as well but I haven't verified that.
I'll put up proper PRs next week, when I'm fully back; for now the branches are here (regalloc2) and here (Cranelift).
Activity
cfallin commentedon Jun 25, 2022
I did some investigation on this yesterday and today (not quite fulltime, I'm still under the weather a bit, but regalloc hacking is still the best way to pass the time...). I found three distinct things I could improve:
Most importantly, some ugly quadratic behavior with liverange splitting. The heuristic has always been "split at first conflict", and a split is always a 2-for-1 deal, not N-for-1. The test program above has a single vreg that is passed as arg0, then arg1, then arg0, then arg1, ... through a long sequence of callsites. This means that it has to be split into N pieces each of which can be put in the appropriate register. Unfortunately splitting had cost O(|bundle|), i.e. proportional to the total length of the bundle. Bad news! My fix to this issue is to "bottom out" at a limit: if a single original bundle is split more than K times (10, for now), go ahead and do an N-for-1 split into minimal pieces.
Also, during splitting, we were copying the
Uselist over to the new second half, and truncating in the first, but notshrink_to_fit'ing. So we had O(n^2) memory at the end of the run too. D'oh.Finally, handling of call-ABI clobbers had a bit too much overhead by treating them as normal defs; I went ahead and resolved an old TODO and used the proper clobbers API, and also adopted a bitmask-based clobbers representation rather than a list. On the Cranelift side the clobbers-list is now a
constbitmask for an ABI rather than a dynamically-built thing with allocations and all the rest.This moved the needle on compilation of the above significantly:
Or in other words, 4x faster compilation and 24x fewer page faults (~= 24x less anon memory used).
In comparison, Wasmtime v0.36 (pre-regalloc2) is:
So v0.36 is ever-so-slightly faster (by ~5%) but curiously the current
main-with-fixes runs ~5% fewer instructions during compilation, just gets a lower IPC. Fewer pagefaults ( == less memory) in current as well. These numbers are close enough to "within noise" I'd want to measure more carefully before making strong claims here. I do feel comfortable saying "anomaly fixed and back to parity" though, given the above.I suspect this may be the same issue we saw in #4045 as well but I haven't verified that.
I'll put up proper PRs next week, when I'm fully back; for now the branches are here (regalloc2) and here (Cranelift).
Limit split count per original bundle with fallback 1-to-N split.
Cranelift: update to latest regalloc2:
Limit split count per original bundle with fallback 1-to-N split.
Limit split count per original bundle with fallback 1-to-N split. (#59)