Bug #77894 [Opn->Csd]: DOMNode::C14N() very slow on generated DOMDocuments even after normalisation
| From: | nielsdos@php.net | Date: | Thu, 08 Jun 2023 17:50:52 +0000 |
| Subject: | Bug #77894 [Opn->Csd]: DOMNode::C14N() very slow on generated DOMDocuments even after normalisation | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-244626@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=77894&edit=1
ID: 77894
Updated by: nielsdos@php.net
Reported by: luxian dot m at gmail dot com
Summary: DOMNode::C14N() very slow on generated DOMDocuments
even after normalisation
-Status: Open
+Status: Closed
Type: Bug
Package: DOM XML related
PHP Version: 7.3.4
-Assigned To:
+Assigned To: nielsdos
Block user comment: N
Private report: N
New Comment:
The fix for this bug has been committed.
If you are still experiencing this bug, try to check out latest source from https://github.com/php/php-src 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.
Previous Comments:
------------------------------------------------------------------------
[2019-04-15 10:19:16] 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()
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=77894&edit=1