Mind The Heap: Techniques For Allocation Free Programming In Scala
summary
Allocation itself costs measurable CPU time; using the Epsilon collector and toggling tlaps shows JVM allocation machinery matters. Returning custom extractor types removes Option allocations; name-based extractors beat the Option version on hot paths. Annotating generics with specialized generics prevents boxing of primitives. Building lists with Seq.apply creates interim Array and ListBuffer objects — using cons is cheaper. An off‑heap cache via sun.misc.Unsafe storing 64‑byte payloads yields far lower GC pressure and much faster runs (benchmarked at 250k, 500k, 1M, 3M events).
AI-written summary · about
