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

Fix memory leak bug #4

Open
wants to merge 3 commits into
base: api-0_0_3_6
Choose a base branch
from
Open

Fix memory leak bug #4

wants to merge 3 commits into from

Conversation

wavewave
Copy link

a few strictness annotation and using proper strict functions makes memory leak go away.

@ttuegel
Copy link

ttuegel commented Mar 23, 2023

Should this target the main branch? I guess we need to pull in upstream changes, too.

@wavewave
Copy link
Author

our current nixpkgs overlay setup on hs-opentelemetry-* is pretty messy right now. we are not using hs-opentelemetry-* from a single commit and for this package, we were actually using hackage 0.0.3.6 version, not from git source. so I first made this on top of 0.0.3.6. (otherwise, the build failed in other places). So refer to this for showing diff. I will make a direct patch for our build and for the upstream of hs-opentelemetry, I will make a PR again. Thanks.

@ttuegel
Copy link

ttuegel commented Mar 23, 2023

I was able to build it on top of main, but I had to vendor all the hs-opentelemetry-* packages.

Copy link

@ttuegel ttuegel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left comments indicating where strictness annotations are not necessary. I have tested these suggestions.

@@ -97,7 +100,7 @@ addAttribute AttributeLimits{..} Attributes{..} k v = case attributeCountLimit o

addAttributes :: ToAttribute a => AttributeLimits -> Attributes -> [(Text, a)] -> Attributes
-- TODO, this could be done more efficiently
addAttributes limits = foldl (\attrs' (k, v) -> addAttribute limits attrs' k v)
addAttributes limits = foldl' (\(!attrs') (!k, !v) -> addAttribute limits attrs' k v)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The bang on attrs' is redundant because we're using foldl':

Suggested change
addAttributes limits = foldl' (\(!attrs') (!k, !v) -> addAttribute limits attrs' k v)
addAttributes limits = foldl' (\attrs' (!k, !v) -> addAttribute limits attrs' k v)

@@ -394,7 +394,7 @@ addAttribute :: (MonadIO m, A.ToAttribute a)
-> a
-- ^ Attribute value
-> m ()
addAttribute (Span s) k v = liftIO $ modifyIORef s $ \i -> i
addAttribute (Span s) k v = liftIO $ modifyIORef' s $ \i -> i `seq` i
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seq is redundant because i comes from the IORef, and now that we use modifyIORef', it is already evaluated.

Suggested change
addAttribute (Span s) k v = liftIO $ modifyIORef' s $ \i -> i `seq` i
addAttribute (Span s) k v = liftIO $ modifyIORef' s $ \i -> i

The other seq in this file are also redundant.

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.

2 participants