Hypothesis
Each LazyResult creates a new Result object (result.js) which allocates: messages array, opts object reference, processor reference, root node. In Workload B, 250 Result objects are created.
The Result class is lightweight, but it initializes a messages array and warnings() method per instance. Since the benchmark processes files synchronously (Processor.process().css), the Result from one file is discarded before the next is created.
Instead of creating a new Result each time, provide a reset() method on Result and reuse the same instance across sequential process() calls from the same Processor:
// In Result:
reset(processor, root, opts) {
this.processor = processor
this.root = root
this.opts = opts
this.css = undefined
this.map = undefined
this.messages.length = 0 // reuse array
}
This eliminates 249 Result object allocations and 249 array allocations for messages.
Editable surface
- lib/result.js — add reset() method
- lib/lazy-result.js — reuse Result instance from Processor cache
What's different from prior work
Expected impact
METRIC_B improvement of 2-4ms from eliminating 249 object+array allocations.
Hypothesis
Each LazyResult creates a new Result object (result.js) which allocates: messages array, opts object reference, processor reference, root node. In Workload B, 250 Result objects are created.
The Result class is lightweight, but it initializes a messages array and warnings() method per instance. Since the benchmark processes files synchronously (Processor.process().css), the Result from one file is discarded before the next is created.
Instead of creating a new Result each time, provide a reset() method on Result and reuse the same instance across sequential process() calls from the same Processor:
This eliminates 249 Result object allocations and 249 array allocations for messages.
Editable surface
What's different from prior work
Expected impact
METRIC_B improvement of 2-4ms from eliminating 249 object+array allocations.