-
Notifications
You must be signed in to change notification settings - Fork 103
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Quadratic time complexity when parsing long recipient stanzas #368
Comments
I see you've pulled out the high-viscosity grease with a lithium complex soap thickener 😆 The performance issue is almost certainly this parser: Lines 191 to 218 in 3ff541a
My expectation is that
We do not know what comes after the stanza (so we can't just break on |
I measured a flamegraph, and indeed the perfomance issue is in The bottleneck is this function: Lines 145 to 152 in 3ff541a
For a given slice, Lines 64 to 89 in 3ff541a
Given an The upshot is that as header length increases, the number of times we will run I suspect the only ways to improve on this are:
|
I added a Before
After
Soooo I guess this means I'm going to add buffered versions of my constructors. The very large header is still quadratic after this change, so I'll still need to consider breaking the type safety of the current types, or at least figure out a way to encapsulate the partial parsing. |
#377 implements the above, which also required I've also confirmed that this change is insufficient for the |
#393 implements I'm going to deploy these performance improvements in |
Environment
rage 0.9.0
What were you trying to do
Decrypt an age file (attached, with test key) with an unusually long (~4MB) recipient stanza body, followed by a normal X25519 stanza.
Expected outcome (it is a completely valid age file, and works fine with
age
):(the above completes near-instantly)
What happened
It takes a near-infinite amount of time to parse, and progress gets exponentially slower. Using
pv
to monitor the progress like so:(pv's ETA grows constantly)
Something similar also happens with a very long recipient type string, but that seems less likely to be a problem in a "real world" scenario, although you might still want to consider it a bug.
Edit: I just learnt about rage's concept of "greasing" - consider this an extreme form of grease, heh
long_recipient.zip
The text was updated successfully, but these errors were encountered: