From c75b6595f6cb0c94f4ecc05ca7c27ec0e83de368 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Sat, 28 Jun 2025 19:47:10 +0300 Subject: feat: implement channel-less grep for 62% performance improvement MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add LineProcessor interface for direct line processing without channels - Implement channel-less file reading in readfile_processor.go - Add optimized reader with 256KB buffering for efficient I/O - Create GrepLineProcessor for direct writing without intermediate channels - Fix serverless mode hanging due to stdin pipe detection - Fix base64 decoding bug (was counting characters instead of arguments) - Fix message output formatting by adding proper newline handling Performance improvements: - Channel-based: 9.00s → Channel-less: 3.42s (62% faster on 100MB files) - Removed channel synchronization overhead and context switching - Reduced memory allocations with buffer pooling Environment variables: - DTAIL_CHANNELLESS_GREP=yes - Enable channel-less implementation - DTAIL_OPTIMIZED_READER=yes - Use optimized buffered reader Known limitation: Inverted grep with context (--invert with --before/--after) not fully implemented in channel-less mode. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- internal/io/line/processor.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 internal/io/line/processor.go (limited to 'internal/io/line/processor.go') diff --git a/internal/io/line/processor.go b/internal/io/line/processor.go new file mode 100644 index 0000000..c7bec77 --- /dev/null +++ b/internal/io/line/processor.go @@ -0,0 +1,22 @@ +package line + +import ( + "bytes" +) + +// Processor defines an interface for processing lines read from files. +// This interface replaces the channel-based approach for better performance. +type Processor interface { + // ProcessLine handles a single line read from a file. + // The line buffer ownership is transferred to the processor. + // Returns error if processing should stop. + ProcessLine(line *bytes.Buffer, lineNum uint64, sourceID string) error + + // Flush ensures any buffered data is written out. + // Called when file reading completes or on periodic intervals. + Flush() error + + // Close cleans up any resources used by the processor. + // Called when processing is complete. + Close() error +} \ No newline at end of file -- cgit v1.2.3