Thanks to visit codestin.com
Credit goes to github.com

Skip to content

bug(#4218): optimize XSL performance#5001

Merged
yegor256 merged 1 commit into
objectionary:masterfrom
maxonfjvipon:bug/#4218/xsl-performance
Apr 19, 2026
Merged

bug(#4218): optimize XSL performance#5001
yegor256 merged 1 commit into
objectionary:masterfrom
maxonfjvipon:bug/#4218/xsl-performance

Conversation

@maxonfjvipon
Copy link
Copy Markdown
Member

@maxonfjvipon maxonfjvipon commented Apr 18, 2026

Summary

  • Replace regex-based tokenize in eo:escape-plus (_funcs.xsl) with contains/substring-before/substring-after β€” avoids regex compilation overhead on every call
  • Remove two no-op eo:escape-plus calls in to-java.xsl's located template: eo:escape-plus($object-name) (top-level object names cannot start with + per grammar) and eo:escape-plus(@loc) (the guard not(contains(@loc, '+')) already guarantees no +)
  • Replace backtracking regex trim in classes.xsl's serialize template with normalize-space

Summary by CodeRabbit

  • Bug Fixes
    • Improved whitespace normalization in serialized text content processing
    • Fixed escape sequence handling in code generation to prevent unintended character transformations
    • Enhanced type safety declarations in string processing utility functions

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 18, 2026

πŸ“ Walkthrough

Walkthrough

Modified 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

Cohort / File(s) Summary
Whitespace Normalization
eo-maven-plugin/src/main/resources/org/eolang/maven/transpile/classes.xsl
Replaced regex-based whitespace extraction with normalize-space() function for trimming and collapsing whitespace in serialized text content.
Escaping Logic Simplification
eo-maven-plugin/src/main/resources/org/eolang/maven/transpile/to-java.xsl, eo-parser/src/main/resources/org/eolang/parser/_funcs.xsl
Removed double-escaping of object names and locations in PhSafe constructor; refactored eo:escape-plus function with explicit type declarations and conditional string operations instead of tokenization.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Suggested reviewers

  • yegor256

Poem

🐰 A rabbit hops through strings so clean,
Escaping twice? No, once is seen!
Whitespace trimmed with grace and care,
Types declared with functions fair,
Simpler code hops through the air! ✨

πŸš₯ Pre-merge checks | βœ… 3
βœ… Passed checks (3 passed)
Check name Status Explanation
Title check βœ… Passed The title accurately describes the main change: optimizing XSL performance by replacing regex operations with more efficient string operations and removing unnecessary function calls.
Docstring Coverage βœ… Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description Check βœ… Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
πŸ§ͺ Generate unit tests (beta)
  • Create PR with unit tests

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.

❀️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link
Copy Markdown
Contributor

πŸš€ Performance Analysis

All 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
Test Base Score PR Score Change % Change Unit Mode
benchmarks.XmirBench.xmirToEO 150.352 151.534 1.182 0.79% ms/op Average Time

⚠️ Performance loss: benchmarks.XmirBench.xmirToEO is slower by 1.182 ms/op (0.79%)

@maxonfjvipon
Copy link
Copy Markdown
Member Author

@yegor256 please take a look, now I see this locally on transplie step:

[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

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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/after removes only the first + β€” matching the prior behavior (prior impl rebuilt the string around the first escaped +). For the current callers (tattr at 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 to translate($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

πŸ“₯ Commits

Reviewing files that changed from the base of the PR and between 89aef7e and 4b56dbc.

πŸ“’ Files selected for processing (3)
  • eo-maven-plugin/src/main/resources/org/eolang/maven/transpile/classes.xsl
  • eo-maven-plugin/src/main/resources/org/eolang/maven/transpile/to-java.xsl
  • eo-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]))"/>
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟑 Minor

🧩 Analysis chain

🏁 Script executed:

cat -n eo-maven-plugin/src/main/resources/org/eolang/maven/transpile/classes.xsl | head -60

Repository: 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 2

Repository: objectionary/eo

Length of output: 631


🏁 Script executed:

git log --oneline --all -20 -- eo-maven-plugin/src/main/resources/org/eolang/maven/transpile/classes.xsl

Repository: objectionary/eo

Length of output: 568


🏁 Script executed:

git show HEAD:eo-maven-plugin/src/main/resources/org/eolang/maven/transpile/classes.xsl | head -60

Repository: objectionary/eo

Length of output: 2424


🏁 Script executed:

git show 4b56dbcf5:eo-maven-plugin/src/main/resources/org/eolang/maven/transpile/classes.xsl | head -60

Repository: 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 -80

Repository: objectionary/eo

Length of output: 102


🏁 Script executed:

git show 4b56dbcf5 -- eo-maven-plugin/src/main/resources/org/eolang/maven/transpile/classes.xsl | head -100

Repository: 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 -150

Repository: objectionary/eo

Length of output: 41


🏁 Script executed:

git log --all --oneline -- eo-maven-plugin/src/main/resources/org/eolang/maven/transpile/classes.xsl

Repository: objectionary/eo

Length of output: 568


🏁 Script executed:

git log --oneline --all -- '**/classes.xsl' | head -20

Repository: 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>&1

Repository: objectionary/eo

Length of output: 102


🏁 Script executed:

git show 4b56dbcf5 --stat

Repository: objectionary/eo

Length of output: 50371


🏁 Script executed:

rg "serialize" eo-maven-plugin/src/main --type xsl -l | head -10

Repository: objectionary/eo

Length of output: 86


🏁 Script executed:

git log --all --oneline | head -30

Repository: 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 -100

Repository: objectionary/eo

Length of output: 87


🏁 Script executed:

git log --all --follow -S "serialize" -- '**/classes.xsl' 2>&1 | head -50

Repository: objectionary/eo

Length of output: 500


🏁 Script executed:

git log -1 --format="%H %s" 4b56dbcf5

Repository: objectionary/eo

Length of output: 161


🏁 Script executed:

git show --stat 4b56dbcf5 | grep -E "^Author|^Date|create|delete" | head -20

Repository: objectionary/eo

Length of output: 202


🏁 Script executed:

git rev-parse HEAD

Repository: 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 status

Repository: 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.

@yegor256 yegor256 merged commit 69af94c into objectionary:master Apr 19, 2026
25 checks passed
@0crat
Copy link
Copy Markdown

0crat commented Apr 21, 2026

@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.

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.

3 participants