Strict Zero-Allocation
In high-frequency robotics (250Hz+), the #1 cause of sudden, non-deterministic jitter is the Java Garbage Collector (GC). Every time you use the new keyword inside a loop, you are creating a tiny bit of “trash” that the CPU eventually has to stop everything and clean up.
1. The Ephemeral Proxy Pattern
MARSLib enforces zero-allocation using Ephemeral Proxies. Instead of creating new Translation2d objects every loop for math, we reuse static, pre-allocated memory buffers.
Try clicking ALLOCATE OBJECT in the simulator below to see how heavy object creation “spikes” the loop time and forces the GC to halt the robot!
2. MARSLib Constraints
The marslib-audit skill strictly forbids the following patterns in “Hot Paths” (periodic loops):
- No
new: UseInputsstructs or static caches. - No Lambdas: Use pre-defined
RunnableorConsumerfields. - No String Building: Use the
Logger.recordOutputraw numeric overloads.
📖 Further Reading & External Resources
- AdvantageKit: Performance & Benchmarking - Technical specifications for zero-allocation logging.
- Java Garbage Collection Tuning - Understanding the impact of object allocation on real-time systems.