|  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: 2023-06-08 17:50 UTC
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: nielsdos (profile)
Status: Closed Package: DOM XML related
PHP Version: 7.3.4 OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
Solve the problem:
49 - 3 = ?
Subscribe to this entry?

 [2019-04-15 10:19 UTC] luxian dot m at gmail dot com
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: (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:

Expected result:
// should be the same as

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


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2023-06-08 17:50 UTC]
-Status: Open +Status: Closed -Assigned To: +Assigned To: nielsdos
 [2023-06-08 17:50 UTC]
The fix for this bug has been committed.
If you are still experiencing this bug, try to check out latest source from and re-test.
Thank you for the report, and for helping us make PHP better.

The main bottleneck was the namespace management. The test code now shows the performance of the different strategies is now almost the exact same. Although there's still more room for improvement in the C14N code itself, this wasn't the main underlying issue here. I'll leave the C14N improvement itself for issue #53655 which already hints at an idea to improve performance.
The fix will be in the 8.3 release.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 22:01:28 2024 UTC