php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #77894 DOMNode::C14N() very slow on generated DOMDocuments even after normalisation
Submitted: 2019-04-15 10:19 UTC Modified: -
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: luxian dot m at gmail dot com Assigned:
Status: Open Package: DOM XML related
PHP Version: 7.3.4 OS:
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2019-04-15 10:19 UTC] luxian dot m at gmail dot com
Description:
------------
Calling DOMNode::C14N() is way slower on DOMDocument objects that are created on the fly compared to DOMDocuments loaded from a string file.

Calling DOMDocument::normalizeDocument() doesn't make a difference despite the documentation stating: "This method acts as if you saved and then loaded the document, putting the document in a "normal" form."


But in the end it's still way faster to get the XML string and load it in a new DOMDocument - which is counter intuitive.

Code to demonstrate this can be found here:
https://gist.github.com/Luxian/1c732d13c12ca03835828a1553c39e4f 
https://3v4l.org/1fFB3 (limited to 200 items to not abuse the platform)

If you run the example code with 500 items you should get something like this:

Testing with 500 items
Generated DOM… 2.56458 seconds
Generated DOM with normalizeDocument()… 2.60349 seconds
Export and re-import DOM… 0.06695 seconds


Test script:
---------------
https://gist.github.com/Luxian/1c732d13c12ca03835828a1553c39e4f 

Expected result:
----------------
$oldDom->normalizeDocument() 
// should be the same as
$newDom->loadXML($oldDom->saveXML());

Actual result:
--------------
40x worse performance when calling C14N() 

Patches

Add a Patch

Pull Requests

Add a Pull Request

 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Mon Apr 22 02:01:25 2019 UTC