perf(parser,metrics): parsing with event-based architecture and FFI optimization#86
Merged
perf(parser,metrics): parsing with event-based architecture and FFI optimization#86
Conversation
…t/endpos - Refactor parser to use event-based callbacks (on_field, on_record_start, on_record_end) - Change on_field signature to pass full line with offset/endpos instead of extracted field text - Remove parse_lines, consolidate into parse_line and parse_records - Move FieldBuffer from metrics_row_builder.lua into metrics_row.lua - Update parser tests to use parse_line instead of parse_lines
Add perfcheck.lua for measuring parser and metrics calculation performance. The script generates configurable test data and measures: - Execution time with warmup iterations - Memory usage (peak and retained) - Throughput (lines/sec)
Replace `string.sub` + `vim.fn.strdisplaywidth` with optimized strings module functions that avoid intermediate string allocations. Benchmark (tests/perfcheck.lua, 100,000 lines x 15 cols): Before: 852ms, 117k lines/sec After: 382ms, 261k lines/sec (~2.2x faster)
Document that `parse_line()` and `create_field_collector()` are not intended for performance-critical paths due to string allocation overhead. Users should use `parse_records()` with event callbacks directly for optimal performance.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Performance
Environment: Windows, 100k rows × 15 columns CSV
Command:
nvim --headless -c "luaf tests/perfcheck.lua" -c "qa!"Perfcheck details (main branch)
Perfcheck details (refactor-metrics branch)
Changes
Metrics Modularization
ColumnTracker(metrics_column.lua) for column width trackingRowMapper(metrics_row_mapper.lua) for physical/logical line mappingmetrics.luato coordinate between modulesParser Event-Based Refactoring
on_linecallback with granular events:on_field,on_record_start,on_record_end,on_commentString Processing Optimization
strings.luamodule with FFI-accelerated functionsdisplay_width()andis_number()that operate directly on offsets without substring extraction