-
Notifications
You must be signed in to change notification settings - Fork 83
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
Space leak in reachOffset' #486
Comments
IIRC this was a conscious decision. I'm open to either updating the documentation to mention this possible performance problem or making the field strict provided the benchmarks are not getting any worse. |
It may be that my memory deceives me though. Happy to make this strict provided there is no performance regression. |
I just realised this isn't true. Is there any circumstance in which one would call |
|
Would you like to open a PR? |
OK: #487 |
The
SourcePos
field ofSt
is lazy:megaparsec/Text/Megaparsec/Stream.hs
Line 358 in cd6302d
This causes a space leak in reachOffset':
megaparsec/Text/Megaparsec/Stream.hs
Lines 419 to 436 in cd6302d
Although the
St
constructor remains evaluated each time around thefoldl'
iteration, theSourcePos
inside does not. Instead it accumulates a large thunk.Now, this doesn't affect
megaparsec
itself, because it only usesreachOffset'
to derivereachOffsett
methods and thereachOffset
methods are never used within the library itself. However, a problem can arise if a client defines aTraversableStream
whosereachOffsetNoLine
method is derived from itsreachOffset
. If thatreachOffset
usesreachOffset'
directly, or indirectly by using one of the built inTraversableStream
instances, then the space leak will manifest itself.Given that
reachOffset
seems no longer used bymegaparsec
perhaps the best long term fix is to deprecate then remove that method. In the short term perhaps you could make that field strict again.The
SourcePos
field was made lazy in e307266 but I don't understand why. I can hardly imagine that allowing this space leak is good for performance.The text was updated successfully, but these errors were encountered: