perf: parallel file processing and faster BibTeX classification#1093
Merged
perf: parallel file processing and faster BibTeX classification#1093
Conversation
bibtex_parser.py: - Pre-compile all preprint patterns into a single combined regex (_ALL_PREPRINT_RE) so _is_preprint_entry does one search instead of iterating 26+ patterns across 7 sub-checkers - _is_preprint_entry now computes _get_preprint_check_content once instead of once per sub-checker (was 7× redundant field reads) - Remove duplicate _is_preprint_entry call in _detect_venue_type; entries reaching that path are already confirmed non-preprint - Pre-compile _detect_venue_type pattern groups (_SYMPOSIUM_RE, _WORKSHOP_RE, _CONFERENCE_RE, _JOURNAL_RE) at module level mass_eval.py: - Process multiple .bib files concurrently using asyncio.Semaphore and asyncio.gather instead of a sequential for-loop - Offload blocking pybtex parse_file_all to a ProcessPoolExecutor (spawn mode) so the event loop is never frozen during parsing; raw_entry field is stripped before pickling back to the main process - Add files_lock (asyncio.Lock) to serialise cross-file mutations on MassEvalState (completed_files, failed_files, checkpoint writes) - Periodic checkpointing moved to a background asyncio task - New --max-parallel-files CLI option (default 8) controls semaphore width and ProcessPoolExecutor size - Add _null_context helper for backward-compatible single-file paths assessment_commands.py / context.py: - Wire --max-parallel-files through Click option and AsyncMassEvalMain protocol
florath
approved these changes
Mar 14, 2026
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
forloop inmass_evalwithasyncio.Semaphore+asyncio.gather, controlled by new--max-parallel-filesoption (default 8). Each file's parse is offloaded to aProcessPoolExecutor(spawn) so the event loop is never blocked._is_preprint_entrynow does a single regex search instead of 7 sub-calls each re-reading 7 fields — eliminates millions of redundant field reads on large files (e.g. 80 K-entry ACL anthology file).files_lock(asyncio.Lock) to serialise cross-file mutations onMassEvalState; periodic checkpointing moved to a background task.Test plan
pytest tests/passes (unit + integration)aletheia-probe mass-eval --helpshows--max-parallel-files[N/total] Processinglines at same timestamp)connection pool exhaustedregression (requires openalex/opencitations platform pool PRs deployed)