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

Re-use resource class for remote sideloads (avoid memory leak) #421

Merged
merged 3 commits into from
Feb 27, 2024

Conversation

PChambino
Copy link
Contributor

Dynamically creating resource classes for each sideload is expensive on
allocations and it was causing a memory leak on carwow's production
applications since these Class objects were not being freed.

Not sure if there was anything in particular to our applications that
was preventing these Class objects from being freed, but even if there
is no memory leak on a simple application, it is still expensive and slow
in terms of allocations.

When running a memory-profiler and doing an HTTP requests that
includes/sideloads resources from a remote resource, you should be able
to see something like:

retained memory by location
-----------------------------------
   2.23 kB  /usr/local/bundle/gems/graphiti-1.3.6/lib/graphiti/query.rb:81

This PR proposes defining a static resource class for remote sideloads
which can be re-used: RemoteSideloadResource.

Dynamically creating resource classes for each sideload is expensive on
allocations and it was causing a memory leak on carwow's production
applications since these Class objects were not being freed.

Not sure if there was anything in particular to our applications that
was preventing these Class objects from being freed, but even if there
is no memory leak on a simple application, it is still expensive and slow
in terms of allocations.

When running a memory-profiler and doing an HTTP requests that
includes/sideloads resources from a remote resource, you should be able
to see something like:

```
retained memory by location
-----------------------------------
   2.23 kB  /usr/local/bundle/gems/graphiti-1.3.6/lib/graphiti/query.rb:81
```

This PR proposes defining a static resource class for remote sideloads
which can be re-used: `RemoteSideloadResource`.
Copy link
Contributor

@richmolj richmolj left a comment

Choose a reason for hiding this comment

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

Makes total sense, thanks ❤️ !

@jkeen jkeen merged commit d3e09c2 into graphiti-api:master Feb 27, 2024
35 checks passed
@PChambino PChambino deleted the remote-sideload-resource-class branch April 19, 2024 10:42
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.

None yet

3 participants