Skip to content

[Performance][Warning] Event buffer pruning uses Array.splice(0,n) causing O(n) copies #660

@OneStepAt4time

Description

@OneStepAt4time

Summary

In events.ts, both eventBuffers and globalEventBuffer are pruned via buffer.splice(0, buffer.length - BUFFER_SIZE). splice() at index 0 shifts all remaining elements, which is O(n). With BUFFER_SIZE = 50, this happens on every event after the buffer fills.

Files Affected

  • src/events.ts (lines 119, 131, 282)

Suggested Fix

Use a circular buffer implementation (fixed-size array with head/tail indices) for O(1) operations.

Metadata

Metadata

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions