citron icon indicating copy to clipboard operation
citron copied to clipboard

Parser seems to spend most of its time doing type metadata lookup

Open BenHetherington opened this issue 1 year ago • 0 comments

When using Citron as an SPM package, the CitronParser protocol (which includes the core parsing code) ends up in a separate module from the generated parser. I found that this led to the parser spending most of its time at runtime in Swift metadata lookup (I don't believe it's able to inline specialise the protocol and inline its code across the module boundary).

I don't still have the Instruments trace handy, but one of the examples I saw was lookup for metadata of a tuple, which seemed to be the one for yyStack.

By gratuitously adding @inlinable to CitronParser (in BenHetherington/citron@87d835c), I was able to reduce the runtime of my project's parser by about 8x (in my test, this took it from over 8 seconds to about 1 second, with the parser running on all cores).

I'm not sure if this is an appropriate solution for this project – it required making a lot of things internal to the Citron module rather than private to CitronParser – but I figured it was worth reporting the performance issue all the same!

BenHetherington avatar Sep 24 '23 17:09 BenHetherington