Skip to content
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

Add 'katipSetContext' which doesn't leak #154

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

jappeace
Copy link

@jappeace jappeace commented Aug 28, 2024

Fixes #153

This introduces an alternative api which allows the following code to run without memory build up.

logLoop :: KatipContextT IO ()
logLoop = do
  katipSetContext "xx" someContext $ do
      $(logTM) InfoS "Hello Katip"
      logLoop

new katipSetContext:

image

compared to katipAddContext:

image

NB, see my reproducer repo for the code that generated these graphs:
https://github.com/jappeace/katip

My initial attempt failed because the map needed to have a strict field (I'm uncertain why).

@ozataman
Copy link
Member

Taking a stab at this without running the code (sorry not able to ATM). The way you're looping, aren't you just repeatedly calling katipAddContext in each loop? So you keep adding/setting context in deeper calls. I assume that you're accumulating large thunks in the data type underlying the sl construction. Instead, you should be a setting the context a single time, then loop the inner part of the code.

@jappeace

This comment was marked as outdated.

@jappeace jappeace marked this pull request as ready for review September 1, 2024 17:46
@jappeace
Copy link
Author

jappeace commented Sep 5, 2024

btw those recent changes made this work ^ @MichaelXavier @ozataman

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add katipSetContext that doesn't leak under recursion
2 participants