Skip to content

Conversation

taylorsilva
Copy link
Member

Changes proposed by this PR

Optimize TimestampedWriter for performance and reduced allocations. Added some tests as well.

Significantly improves performance of TimestampedWriter by implementing several optimizations:

  • Uses a buffer pool to eliminate allocations between Write calls
  • Processes input by segments between newlines rather than byte-by-byte
  • Optimizes timestamp formatting with direct byte manipulation
  • Pre-allocates and reuses buffers for newline tracking

Benchmark improvements:

  • Eliminated allocations in most operations (0 allocs/op)
  • Medium inputs with timestamps improved from 445.8 ns/op to 168.2 ns/op
  • Large inputs with timestamps improved from 2284 ns/op to 871.2 ns/op
  • 6x faster for SetTimestamp operations
  • Maintains exact same output behavior

Release Note

  • Improve performance of fly watch

…dd test

Significantly improves performance of TimestampedWriter by implementing several
optimizations:

- Uses a buffer pool to eliminate allocations between Write calls
- Processes input by segments between newlines rather than byte-by-byte
- Optimizes timestamp formatting with direct byte manipulation
- Pre-allocates and reuses buffers for newline tracking

Benchmark improvements:
- Eliminated allocations in most operations (0 allocs/op)
- Medium inputs with timestamps improved from 445.8 ns/op to 168.2 ns/op
- Large inputs with timestamps improved from 2284 ns/op to 871.2 ns/op
- 6x faster for SetTimestamp operations
- Maintains exact same output behavior

Signed-off-by: Mathias Bogaert <mathias.bogaert@gmail.com>
Co-authored-by: Taylor Silva <dev@taydev.net>
@taylorsilva taylorsilva requested a review from a team as a code owner March 5, 2025 22:07
@taylorsilva taylorsilva merged commit 2c80e78 into master Mar 6, 2025
11 checks passed
@taylorsilva taylorsilva deleted the fly-writer branch March 6, 2025 00:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants