CoreOffice / XMLCoder

Easy XML parsing using Codable protocols in Swift
https://coreoffice.github.io/XMLCoder/
MIT License
801 stars 112 forks source link

Optimise parsing by removing excessive copying. #278

Closed maciejtrybilo closed 9 months ago

maciejtrybilo commented 11 months ago

In the current implementation the copy-on-write causes excessive copying when building the box tree.

I've inlined the merge function into transformToBoxTree and used a storage variable to avoid it being passed around and copied.

In my tests this results in a ~30x speedup and makes all the difference in my use case.

Also IMO the code is a little clearer now as it shows the recursive nature of the algorithm in one function.