Commit 25d49ee
perf: JavaScript parser performance improvements (#614)
* perf: JavaScript parser performance improvements
- Token type constants: Changed from Symbol to numeric constants for faster comparison
- Location tracking: Now disabled by default (add trackLocation: true for token location info)
- Lazy position tracking: Error messages include position info even when trackLocation: false
- Unified token structure: Reduced token count by combining delimiter info into field tokens
- Object.create(null) for records: ~3.6x faster object creation
- Non-destructive buffer reading: Reduced GC pressure by 46%
- Regex removal for unquoted fields: ~15% faster parsing
- String comparison optimization: ~10% faster
- Quoted field parsing optimization: Eliminated overhead
Benchmark results:
- 1,000 rows: 3.57 ms → 1.77 ms (50% faster)
- 5,000 rows: 19.47 ms → 8.96 ms (54% faster)
- Throughput: 23.8 MB/s → 49.0 MB/s (2.06x improvement)
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
* fix: update new factory function tests to use unified token format
Update createStringCSVLexerTransformer.spec.ts and
createCSVRecordAssemblerTransformer.spec.ts to use the new
unified token structure with Delimiter enum instead of
separate Field/FieldDelimiter/RecordDelimiter token types.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
* style: format code
* fix: update test expectations for new parser behavior
Missing CSV fields now return empty string instead of undefined.
Updated test expectations in:
- StringCSVParserStream.test.ts
- BinaryCSVParserStream.test.ts
- parseBinaryToIterableIterator.test.ts
- parse.spec.ts
* fix: change toStrictEqual to toEqual in browser tests
Object.create(null) records don't match toStrictEqual due to prototype
differences. Changed to toEqual to properly compare object values.
Updated test files:
- parseResponse.browser.spec.ts
- parseBinaryStream.browser.spec.ts
- parseBinary.browser.spec.ts
* fix: remove concurrent test execution in stream tests
Stream tests were hanging in CI and locally when run in parallel.
Removed .concurrent from describe and it blocks in:
- StringCSVParserStream.test.ts
- BinaryCSVParserStream.test.ts
* refactor: use direct vitest imports in stream tests
Removed unnecessary aliases for describe and it.
Directly importing from vitest is cleaner and more standard.
* style: format test files
Applied biome formatting to:
- src/parser/stream/StringCSVParserStream.test.ts
- src/parser/stream/BinaryCSVParserStream.test.ts
* feat(parser): enhance FlexibleStringCSVLexer with reusable array pooling
- Implemented ReusableArrayPool to optimize memory usage for string segments in FlexibleStringCSVLexer.
- Updated FlexibleStringCSVLexer to utilize the new array pool for segment management, improving performance in parsing.
- Adjusted token handling to ensure correct delimiter usage, replacing EOF with Record where appropriate.
- Modified tests in CSVRecordAssemblerTransformer and StringCSVLexerTransformer to reflect changes in token structure and delimiter handling.
- Cleaned up test cases for better readability and consistency.
* Pad record-view fill rows in fill strategy
* Add record-view assembler and tighten column strategies
* revert: remove CSVRecordView feature
CSVRecordView機能を削除し、過剰な最適化を切り戻しました。
object形式のcolumnCountStrategy制限(fill/strictのみ)は維持されています。
- FlexibleCSVRecordViewAssembler関連のファイルを削除
- types.tsからCSVRecordView型と'record-view' outputFormatを削除
- FlexibleCSVObjectRecordAssemblerからrecord-view機能を削除
- 関連するテストとドキュメントを更新
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
* feat: apply const type parameters consistently across all parser classes
プロジェクト全体でconst type parametersを一貫して適用しました。
変更内容:
- FlexibleCSVArrayRecordAssembler
- FlexibleCSVObjectRecordAssembler
- FlexibleStringArrayCSVParser
- FlexibleStringObjectCSVParser
- FlexibleBinaryArrayCSVParser
- FlexibleBinaryObjectCSVParser
すべてのクラスで`Header extends ReadonlyArray<string>`を
`const Header extends ReadonlyArray<string>`に変更。
これにより、ユーザーは`as const`を書かなくてもリテラル型が
正しく推論されるようになりました:
Before: header: ['name', 'age'] as const
After: header: ['name', 'age']
テスト:1341個すべて成功
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
* fix: address code review comments
レビューコメントに基づいて以下を修正:
1. parseResponse.spec.ts - describeブロック名を修正(parseRequest → parseResponse)
2. column-count-strategy-rename.md - breaking changeをminorに変更し、移行ガイドを追加
3. performance-improvements.md - ベンチマーク結果の記述を修正(46% → 83% faster)
4. vitest.setup.ts - endOnFailureのコメントを正確に修正(デフォルトはfalse)
5. createStringCSVLexer.ts - 戻り値の型にTrackLocationジェネリックを追加
すべてのテストが成功(1341個)
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
* test: improve StringCSVLexerTransformer test quality and update benchmarks
- Remove debug options ({ numRuns: 10 }) to restore full property-based test coverage
- Add .flat() to transform result in third test for correct array shape matching
- Fix edge case: empty CSV string should produce no tokens
- Update performance numbers with final benchmark measurements:
- Object format (1,000 rows): 61.2 MB/s (was 49.0 MB/s)
- Object format (5,000 rows): 67.9 MB/s (was 53.3 MB/s)
- Array format (1,000 rows): 87.6 MB/s (was 89.6 MB/s)
- Array format (5,000 rows): 86.4 MB/s (new measurement)
- Array format is 43% faster (1.43× throughput) vs Object format
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
* style: improve formatting of expected tokens in StringCSVLexerTransformer tests
* test: consolidate test files and improve coverage config
- Consolidate FlexibleCSVRecordAssembler test files (6 → 2 files)
- Merged array-output, field-count-limit, object-output, and prototype-safety tests into .test.ts
- All 77 tests passing
- Consolidate FlexibleStringCSVLexer test files (4 → 2 files)
- Merged buffer-overflow and undefined-check tests into .test.ts
- All 33 tests passing
- Improve coverage configuration in vite.config.ts
- Add explicit exclude patterns for test files
- Add reporter configuration
- Set reportsDirectory
- Add @vitest/coverage-v8 to devDependencies for future migration
Total: 110 test cases passing
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
* refactor: enhance comments and improve header handling in FlexibleCSVRecordAssembler tests
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent 8adf5d9 commit 25d49ee
File tree
65 files changed
+4302
-3165
lines changed- .changeset
- benchmark
- config
- docs/reference
- src
- core
- parser
- api
- binary
- file
- model
- network
- stream
- string
- models
- stream
- utils/memory
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
65 files changed
+4302
-3165
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
8 | | - | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
9 | 14 | | |
10 | 15 | | |
11 | 16 | | |
| |||
14 | 19 | | |
15 | 20 | | |
16 | 21 | | |
17 | | - | |
| 22 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
5 | 7 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
218 | 218 | | |
219 | 219 | | |
220 | 220 | | |
| 221 | + | |
221 | 222 | | |
222 | 223 | | |
223 | 224 | | |
| |||
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
100 | 100 | | |
101 | 101 | | |
102 | 102 | | |
103 | | - | |
104 | | - | |
105 | | - | |
106 | | - | |
107 | | - | |
108 | | - | |
109 | | - | |
110 | | - | |
111 | | - | |
112 | | - | |
113 | | - | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
114 | 108 | | |
115 | 109 | | |
116 | | - | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
0 commit comments