Load pp only when XPath debug tracing is enabled - #365
Open
tas50 wants to merge 1 commit into
Open
Conversation
xpath_parser.rb requires pp at the top of the file, but PP is used in exactly one place: XPathParser#trace, reached only through enter and leave, and every one of those call sites is guarded by `if @debug`. @debug comes from DEBUG, which is false unless the environment variable REXML_XPATH_PARSER_DEBUG is set to "true". So every REXML user loads pp and prettyprint for a debugging aid that is off by default. Measured on Ruby 4.0.6 (arm64-darwin), best of seven runs: require "rexml/document" files loaded before 23.85 ms 38 after 21.72 ms 36 -2.13 ms -2 (9% faster) Small in absolute terms, but REXML sits underneath a lot of the ecosystem and the change carries no behavior risk. Debug tracing still works: running with REXML_XPATH_PARSER_DEBUG=true produces the same trace output as before. Test suite: 811 tests, 0 failures, unchanged. The three added tests cover that requiring rexml/document does not load pp, that XPath matching works without it, and that evaluating an XPath does not pull it in. Two of them fail against the previous code. Signed-off-by: Tim Smith <tsmith84@proton.me>
Member
|
Could you share what is your real world problem? |
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.
Problem
lib/rexml/xpath_parser.rbrequiresppat the top of the file.PPis used in exactly one place:traceis reached only throughenterandleave, and every call site is guarded byif @debug(lines 225, 228, 246, 292, 373, 651, 690, 695, 769, 773, 781, 800).@debugcomes fromDEBUG, which is:So every REXML user loads
ppandprettyprintfor a debugging aid that is off by default.Fix
Move the require into
#trace, the only method that touchesPP.Measurements
Ruby 4.0.6 (arm64-darwin), best of seven runs:
require "rexml/document"Small in absolute terms, but REXML sits underneath a good deal of the ecosystem, and the change carries no behavior risk.
Debug tracing is unaffected — running with
REXML_XPATH_PARSER_DEBUG=trueproduces the same trace output:Tests
test/run.rb: 811 tests, 0 failures, unchanged (814 with the additions).The three added tests cover that requiring
rexml/documentdoes not loadpp, that XPath matching works without it, and that evaluating an XPath does not pull it in. Two of them fail against the previous code.