Skip to content

Improve Performance with Nested CDATA #243

@Masamuneee

Description

@Masamuneee

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions