Skip to Content
marmot

Reviewer: frontend (map lowering, codegen fast paths). Note under review: Design: map tables that split.

What the code generator depends on

  • Only runtime function names and signatures. These are mapaccess1 and mapaccess2 with their _fast32, _fast64, _faststr and _fast128 forms, and mapassign and its fast forms. Also mapdelete, mapiterinit, mapiternext, maplen, mapclear and makemap. len(m) is a call to maplen, not a load of a header field, so the map header layout is free to change.
  • runtime.hiter: the code generator takes the type from the runtime package through the type checker and allocates it as a stack slot per range loop. A larger hiter is fine, but it is one frame slot per map range loop, and frames on native goroutine stacks do not grow. Keep it near today's size (add one table pointer and a depth, not a copy of directory state).
  • Map read-modify-write fusion (MARMOT_MAPFUSE): v := m[k]. .... m[k] = w becomes one mapassign whose returned slot is stored to after arithmetic that cannot call, load or store. Rule to keep: the slot that mapassign returns stays valid until the next write to the map (insert, delete, clear). A split or in-place doubling only on insert keeps this.
  • Constant map literals (maplit) are built at init with a loop of mapassign. No static map image is emitted, so the layout change needs no codegen change. Large literals (tuios fa.init, icons.init) will now split tables during init: measure startup time on tuios.
  • The go dialect's go.map_lookup lowers to the same runtime calls in the backend. No change there.

What breaks or needs a rule

  1. Hash bits: the directory index takes the top bits. The group probe inside a table must use bits that do not overlap them. Go uses the low bits for h1 and the top 7 bits of the low word for h2. Otherwise every table after a split sees a skewed probe distribution.
  2. Slot stability for fusion, as above: no growth or split on lookup or on a mapassign of an existing key.
  3. reflect.MapIter and maps.Clone reach the runtime through linkname: their signatures must stay.
  4. Iteration over a table that split while the old table is kept: the code generator calls mapiternext once per loop step. It reads key and element through the key and elem pointers of the hiter. Those pointers must point into the table the iterator holds (old or current), not into a table freed early.

What to measure, in addition to the note's list

  • tuios startup (process start to main) and its map-heavy init, dev and -release.
  • The size of hiter and the frame growth of functions with map range loops.
  • mapassign_fast64 and mapaccess1_fast64 instruction counts on mapint. One more load per operation is expected. Check that the directory index does not add a division or a second hash.

On this page

Was this page helpful?

Report an issueOpen issues