bug(#4218): optimize XSL performance#5001
Conversation
β¦lize Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
π WalkthroughWalkthroughModified XSLT whitespace normalization in classes.xsl, removed double-escaping of object names and locations in to-java.xsl PhSafe constructor calls, and refactored the eo:escape-plus function implementation with explicit type declarations in _funcs.xsl. Changes
Estimated code review effortπ― 2 (Simple) | β±οΈ ~10 minutes Suggested reviewers
Poem
π₯ Pre-merge checks | β 3β Passed checks (3 passed)
βοΈ Tip: You can configure your own custom pre-merge checks in the settings. β¨ Finishing Touchesπ§ͺ Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
π Performance AnalysisAll benchmarks are within the acceptable range. No critical degradation detected (threshold is 100%). Please refer to the detailed report for more information. Click to see the detailed report
|
|
@yegor256 please take a look, now I see this locally on [INFO] --- eo:1.0-SNAPSHOT:transpile (compile) @ eo-runtime ---
[INFO] Transpiled 97 XMIRs, created 8 Java files in eo-runtime/target/generated-sources
[INFO] The directory added to Maven 'compile-source-root': eo-runtime/target/generated-sources
[INFO] The directory added to Maven 'test-compile-source-root': eo-runtime/target/generated-test-sources
[INFO] Transpilation took 97ms in total |
There was a problem hiding this comment.
Actionable comments posted: 1
π§Ή Nitpick comments (1)
eo-parser/src/main/resources/org/eolang/parser/_funcs.xsl (1)
168-171: Semantics preserved; nice perf win.Replacing the regex/tokenize approach with
contains+substring-before/afterremoves only the first+β matching the prior behavior (prior impl rebuilt the string around the first escaped+). For the current callers (tattrat Line 789 and test helpers at Lines 811/815/844), names contain at most one sentinel+, so the single-occurrence semantics are correct.One minor note: if a future caller passes a string with multiple
+characters expecting all to be stripped, this function will silently leave the remaining ones in place. Consider a short XSLT comment documenting that only the first+is removed, or switch totranslate($name, '+', '')if all-stripping is the intended contract.π€ Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@eo-parser/src/main/resources/org/eolang/parser/_funcs.xsl` around lines 168 - 171, The new eo:escape-plus function only removes the first '+' (using contains + substring-before/after), which may surprise future callers; either add a short XSLT comment above the eo:escape-plus function documenting that it intentionally strips only the first '+' (since current callers like tattr and test helpers expect at most one), or change the implementation to remove all '+' occurrences by replacing the body with translate($name, '+', '') if the intended contract is to strip every '+'.
π€ Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@eo-maven-plugin/src/main/resources/org/eolang/maven/transpile/classes.xsl`:
- Line 23: Change the $content variable to preserve original whitespace by
selecting string(text()[1]) instead of normalize-space(...), and introduce a new
$blank variable computed as normalize-space($content) = '' to keep using
whitespace-collapsing for emptiness checks (replace uses in the conditional
checks that currently rely on normalize-space at the spots referencing
$content); ensure $content is used when writing to <xmir> so multiple internal
spaces are preserved, and add a short comment explaining the intent (or add a
test) if normalization was actually intended.
---
Nitpick comments:
In `@eo-parser/src/main/resources/org/eolang/parser/_funcs.xsl`:
- Around line 168-171: The new eo:escape-plus function only removes the first
'+' (using contains + substring-before/after), which may surprise future
callers; either add a short XSLT comment above the eo:escape-plus function
documenting that it intentionally strips only the first '+' (since current
callers like tattr and test helpers expect at most one), or change the
implementation to remove all '+' occurrences by replacing the body with
translate($name, '+', '') if the intended contract is to strip every '+'.
πͺ Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
βΉοΈ Review info
βοΈ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 4372f6d6-032e-428d-8826-0853c1b8258b
π Files selected for processing (3)
eo-maven-plugin/src/main/resources/org/eolang/maven/transpile/classes.xsleo-maven-plugin/src/main/resources/org/eolang/maven/transpile/to-java.xsleo-parser/src/main/resources/org/eolang/parser/_funcs.xsl
| <xsl:text>"</xsl:text> | ||
| </xsl:for-each> | ||
| <xsl:variable name="content" select="replace(text()[1], '^\s*(.+?)\s*$', '$1')"/> | ||
| <xsl:variable name="content" select="normalize-space(string(text()[1]))"/> |
There was a problem hiding this comment.
π§© Analysis chain
π Script executed:
cat -n eo-maven-plugin/src/main/resources/org/eolang/maven/transpile/classes.xsl | head -60Repository: objectionary/eo
Length of output: 2844
π Script executed:
rg '\$content' eo-maven-plugin/src/main/resources/org/eolang/maven/transpile/classes.xsl -n -A 2 -B 2Repository: objectionary/eo
Length of output: 631
π Script executed:
git log --oneline --all -20 -- eo-maven-plugin/src/main/resources/org/eolang/maven/transpile/classes.xslRepository: objectionary/eo
Length of output: 568
π Script executed:
git show HEAD:eo-maven-plugin/src/main/resources/org/eolang/maven/transpile/classes.xsl | head -60Repository: objectionary/eo
Length of output: 2424
π Script executed:
git show 4b56dbcf5:eo-maven-plugin/src/main/resources/org/eolang/maven/transpile/classes.xsl | head -60Repository: objectionary/eo
Length of output: 2424
π Script executed:
git diff 4b56dbcf5^..4b56dbcf5 -- eo-maven-plugin/src/main/resources/org/eolang/maven/transpile/classes.xsl | head -80Repository: objectionary/eo
Length of output: 102
π Script executed:
git show 4b56dbcf5 -- eo-maven-plugin/src/main/resources/org/eolang/maven/transpile/classes.xsl | head -100Repository: objectionary/eo
Length of output: 3739
π Script executed:
git log -p --max-count=3 -S "normalize-space" -- eo-maven-plugin/src/main/resources/org/eolang/maven/transpile/classes.xsl | head -150Repository: objectionary/eo
Length of output: 41
π Script executed:
git log --all --oneline -- eo-maven-plugin/src/main/resources/org/eolang/maven/transpile/classes.xslRepository: objectionary/eo
Length of output: 568
π Script executed:
git log --oneline --all -- '**/classes.xsl' | head -20Repository: objectionary/eo
Length of output: 764
π Script executed:
git show 4b56dbcf5~1:eo-maven-plugin/src/main/resources/org/eolang/maven/transpile/classes.xsl 2>&1Repository: objectionary/eo
Length of output: 102
π Script executed:
git show 4b56dbcf5 --statRepository: objectionary/eo
Length of output: 50371
π Script executed:
rg "serialize" eo-maven-plugin/src/main --type xsl -l | head -10Repository: objectionary/eo
Length of output: 86
π Script executed:
git log --all --oneline | head -30Repository: objectionary/eo
Length of output: 2242
π Script executed:
git diff HEAD~1 HEAD -- eo-maven-plugin/src/main/resources/org/eolang/maven/transpile/classes.xsl 2>&1 | head -100Repository: objectionary/eo
Length of output: 87
π Script executed:
git log --all --follow -S "serialize" -- '**/classes.xsl' 2>&1 | head -50Repository: objectionary/eo
Length of output: 500
π Script executed:
git log -1 --format="%H %s" 4b56dbcf5Repository: objectionary/eo
Length of output: 161
π Script executed:
git show --stat 4b56dbcf5 | grep -E "^Author|^Date|create|delete" | head -20Repository: objectionary/eo
Length of output: 202
π Script executed:
git rev-parse HEADRepository: objectionary/eo
Length of output: 99
π Script executed:
git log -1 --pretty=format:"%H %s"Repository: objectionary/eo
Length of output: 161
π Script executed:
# Check if this is a currently-being-reviewed PR or already committed
git statusRepository: objectionary/eo
Length of output: 124
Clarify intent of normalize-space() for text serialization.
Line 23 uses normalize-space() which removes leading/trailing whitespace and collapses internal whitespace sequences into single spaces. Since $content is directly output to <xmir> on Line 28, this will alter text like a b (multiple spaces) to a b (single space).
If the XMIR output should preserve the exact whitespace from source text nodes, use string(text()[1]) for content and handle blank-checking separately:
<xsl:variable name="content" select="string(text()[1])"/>
<xsl:variable name="blank" select="normalize-space($content) = ''"/>Then use $blank for emptiness checks (lines 24, 40) while keeping $content for output.
If whitespace normalization is intentional for this serialization, document why and add a test case to verify the expected behavior with text nodes containing significant whitespace.
π€ Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@eo-maven-plugin/src/main/resources/org/eolang/maven/transpile/classes.xsl` at
line 23, Change the $content variable to preserve original whitespace by
selecting string(text()[1]) instead of normalize-space(...), and introduce a new
$blank variable computed as normalize-space($content) = '' to keep using
whitespace-collapsing for emptiness checks (replace uses in the conditional
checks that currently rely on normalize-space at the spots referencing
$content); ensure $content is used when writing to <xmir> so multiple internal
spaces are preserved, and add a short comment explaining the intent (or add a
test) if normalization was actually intended.
|
@maxonfjvipon Great work on your contribution! π You've earned +12 points (+16 base, -4 for 13 hits-of-code). Keep up the momentum - your total score is now +103! Don't forget to check your Zerocracy account for updates. |
Summary
tokenizeineo:escape-plus(_funcs.xsl) withcontains/substring-before/substring-afterβ avoids regex compilation overhead on every calleo:escape-pluscalls into-java.xsl'slocatedtemplate:eo:escape-plus($object-name)(top-level object names cannot start with+per grammar) andeo:escape-plus(@loc)(the guardnot(contains(@loc, '+'))already guarantees no+)classes.xsl'sserializetemplate withnormalize-spaceSummary by CodeRabbit