8000 Improve `Text.check` performance (#256) · ruby/rexml@3dc9eca · GitHub
[go: up one dir, main page]

Skip to content

Commit 3dc9eca

Browse files
authored
Improve Text.check performance (#256)
The doctype parameter of Text.check is not being used. Changing the doctype parameter to an optional parameter improves the parsing speed of the DOM. ## Benchmark ``` before after before(YJIT) after(YJIT) dom 19.854 23.805 33.969 37.712 i/s - 100.000 times in 5.036779s 4.200839s 2.943877s 2.651709s sax 29.436 30.494 54.070 55.089 i/s - 100.000 times in 3.397155s 3.279348s 1.849463s 1.815255s pull 34.908 34.857 62.969 64.895 i/s - 100.000 times in 2.864651s 2.868842s 1.588082s 1.540939s stream 34.570 34.281 60.616 60.355 i/s - 100.000 times in 2.892656s 2.917080s 1.649737s 1.656866s Comparison: dom after(YJIT): 37.7 i/s before(YJIT): 34.0 i/s - 1.11x slower after: 23.8 i/s - 1.58x slower before: 19.9 i/s - 1.90x slower sax after(YJIT): 55.1 i/s before(YJIT): 54.1 i/s - 1.02x slower after: 30.5 i/s - 1.81x slower before: 29.4 i/s - 1.87x slower pull after(YJIT): 64.9 i/s before(YJIT): 63.0 i/s - 1.03x slower before: 34.9 i/s - 1.86x slower after: 34.9 i/s - 1.86x slower stream before(YJIT): 60.6 i/s after(YJIT): 60.4 i/s - 1.00x slower before: 34.6 i/s - 1.75x slower after: 34.3 i/s - 1.77x slower ``` - YJIT=ON : 1.00x - 1.11x faster (dom: 1.11x faster) - YJIT=OFF : 1.00x - 1.20x faster (dom: 1.20x faster)
1 parent e80ffdd commit 3dc9eca

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

lib/rexml/attribute.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ def element=( element )
173173
@element = element
174174

175175
if @normalized
176-
Text.check( @normalized, NEEDS_A_SECOND_CHECK, doctype )
176+
Text.check( @normalized, NEEDS_A_SECOND_CHECK )
177177
end
178178

179179
self

lib/rexml/text.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,16 +104,16 @@ def initialize(arg, respect_whitespace=false, parent=nil, raw=nil,
104104
@entity_filter = entity_filter if entity_filter
105105
clear_cache
106106

107-
Text.check(@string, illegal, doctype) if @raw
107+
Text.check(@string, illegal) if @raw
108108
end
109109

110110
def parent= parent
111111
super(parent)
112-
Text.check(@string, NEEDS_A_SECOND_CHECK, doctype) if @raw and @parent
112+
Text.check(@string, NEEDS_A_SECOND_CHECK) if @raw and @parent
113113
end
114114

115115
# check for illegal characters
116-
def Text.check string, pattern, doctype
116+
def Text.check string, pattern, doctype = nil
117117

118118
# illegal anywhere
119119
if !string.match?(VALID_XML_CHARS)

test/test_text_check.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ module REXMLTests
44
class TextCheckTester < Test::Unit::TestCase
55

66
def check(string)
7-
REXML::Text.check(string, REXML::Text::NEEDS_A_SECOND_CHECK, nil)
7+
REXML::Text.check(string, REXML::Text::NEEDS_A_SECOND_CHECK)
88
end
99

1010
def assert_check(string)

0 commit comments

Comments
 (0)
0