Skip to content

perf(parser): 4 targeted optimizations for NZB import pipeline#347

Merged
javi11 merged 1 commit intomainfrom
perf/parser-optimizations
Feb 26, 2026
Merged

perf(parser): 4 targeted optimizations for NZB import pipeline#347
javi11 merged 1 commit intomainfrom
perf/parser-optimizations

Conversation

@javi11
Copy link
Copy Markdown
Owner

@javi11 javi11 commented Feb 26, 2026

Summary

  • Parallelize yEnc header fetches in normalizeSegmentSizesWithYenc: 2nd and last segment fetches now run concurrently via errgroup.WithContext — ~50% wall-time reduction per file with 3+ segments
  • Pre-compile obfuscation regex patterns in fileinfo/fileinfo.go: 4 patterns promoted to package-level *regexp.Regexp vars, eliminating sync.Map lookups on every filename evaluation (called 3× per file)
  • Consolidate binary.Read calls in par2/reader.go: 4 separate reads of the 56-byte FileDescriptor header collapsed into a single fixed-struct read
  • Use bytes.Equal in HasMagicBytes (par2/detector.go): replaces manual 8-byte loop with SIMD-backed bytes.Equal, consistent with fileinfo/detector.go style

Test plan

  • go build ./internal/importer/parser/... passes
  • go test ./internal/importer/parser/... passes (all existing tests green)
  • Manual: import a 100+ file NZB with multi-segment files and compare parse wall time vs main

🤖 Generated with Claude Code

- Parallelize yEnc header fetches (2nd + last segment) in
  normalizeSegmentSizesWithYenc using errgroup.WithContext, cutting
  normalization wall time ~50% for files with 3+ segments
- Pre-compile 4 obfuscation regex patterns in fileinfo as package-level
  vars, eliminating sync.Map lookups on every filename evaluation
- Consolidate 4 binary.Read calls in PAR2 ReadFileDescriptor into a
  single fixed-struct read (56 bytes in one shot)
- Replace 8-byte loop in HasMagicBytes with bytes.Equal for SIMD-backed
  comparison, consistent with fileinfo/detector.go style

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@javi11 javi11 merged commit d5fcd34 into main Feb 26, 2026
1 check passed
@javi11 javi11 deleted the perf/parser-optimizations branch February 26, 2026 14:08
drondeseries referenced this pull request in drondeseries/altmount_old Apr 16, 2026
- Parallelize yEnc header fetches (2nd + last segment) in
  normalizeSegmentSizesWithYenc using errgroup.WithContext, cutting
  normalization wall time ~50% for files with 3+ segments
- Pre-compile 4 obfuscation regex patterns in fileinfo as package-level
  vars, eliminating sync.Map lookups on every filename evaluation
- Consolidate 4 binary.Read calls in PAR2 ReadFileDescriptor into a
  single fixed-struct read (56 bytes in one shot)
- Replace 8-byte loop in HasMagicBytes with bytes.Equal for SIMD-backed
  comparison, consistent with fileinfo/detector.go style

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant