Make wrapper generation more efficient - #126
Draft
kwabenantim wants to merge 1 commit into
Draft
Conversation
Profiling a from-scratch pychaste generation (758s) showed most of the time was cppwg's own Python, not CastXML. Two hot spots dominated: 1. The `Path(a) in Path(b).parents` idiom, evaluated per declaration and per file across several phases (the source-declaration filter, unknown- class logging, auto-include resolution, file collection), allocated millions of Path objects and did O(depth) string-normalized compares. Replace it with utils.path_is_within(), a lexical normalized-string test with the same (strict, no-symlink) semantics as Path.parents. 2. ModuleInfo.sort_classes ran two C-by-C loops over the module's classes (~270 for pychaste) with utils.type_string_matches() inside, re- canonicalizing and re-compiling the same regex on every comparison (~11M re.sub calls). Precompute each class's canonical argument-type strings and a compiled whole-token regex for its name once, and cache the pairwise `requires` result. Factor the pattern build out of type_string_matches() into utils.compile_type_pattern() so both share it. Also hoist the loop-invariant realpath() out of the per-declaration loop in CppSourceParser.parse_instantiations(). These are equivalence-preserving refactors: the 274 pychaste wrappers are byte-for-byte identical, the shapes example regenerates identically, and the 480 unit tests pass. Measured on pychaste: 758.7s -> 275.2s (-64%), with parse_headers -223s, resolve_auto_includes -77s, sort_classes -75s, log_unknown_classes -57s. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #126 +/- ##
===========================================
- Coverage 99.75% 99.59% -0.16%
===========================================
Files 31 31
Lines 2475 2488 +13
Branches 534 535 +1
===========================================
+ Hits 2469 2478 +9
- Misses 5 9 +4
Partials 1 1
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
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.
Fixes #125