Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Improve Performance with Nested CDATA #243

Open
Masamuneee opened this issue Feb 26, 2025 · 0 comments
Open

Improve Performance with Nested CDATA #243

Masamuneee opened this issue Feb 26, 2025 · 0 comments

Comments

@Masamuneee
Copy link

I think we should improve the implementation to handle nested CDATA more efficiently.

require "rexml/document"

include REXML  

(1..1000000000).step(10000000) do |depth|
  puts "Trying depth #{depth}"
  string = "<?xml version=\"1.0\"?>\n" +
           "<root>Test</root>\n" +
           "<!" + "[CDATA[" * depth + "]]>\n"
  
  start = Time.now
  begin
    doc = Document.new(string)
  rescue Exception => e
    puts "Error at depth #{depth}: #{e}"
    break
  end
  elapsed_time = Time.now - start
  puts "Elapsed time: #{elapsed_time} seconds"
end

Result:

Elapsed time: 24.994068928 seconds
Trying depth 200000001
Elapsed time: 27.070803532 seconds
Trying depth 210000001
Elapsed time: 27.870487966 seconds
Trying depth 220000001
Elapsed time: 28.787843908 seconds
Trying depth 230000001
[1]    4336 killed     ruby test.rb
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Development

No branches or pull requests

1 participant