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 Relationship.instances cache. #477

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

Conversation

marshall-lee
Copy link

This PR aims to fix several issues with Relationship cache:

  1. It's not threadsafe, so I propose to use a TLS variable for this.
  2. Memory obtained by cache remains non-freed before the next run of serialize. I think it should be freed immediately.
  3. Memory should be freed in ensure block to prevent memory bloating in case of exception.

There are only two hard things in Computer Science: cache invalidation and naming things.

@marshall-lee
Copy link
Author

Hmm, fails only on Ruby 1.9

@randym
Copy link
Owner

randym commented Nov 3, 2016

@marshall-lee would you be kind enough to rebase and add specs for your changes?

@randym
Copy link
Owner

randym commented May 9, 2017

@marhall-lee are you still interested in solving this problem?

fxfilmxf added a commit to Catalectic/axlsx that referenced this pull request Sep 7, 2017
fxfilmxf added a commit to Catalectic/axlsx that referenced this pull request Sep 7, 2017
@guilpejon
Copy link

guilpejon commented Jun 14, 2018

Ran into this problem today. Luckly I was able to fork the master branch and apply this patch to make axlsx work asynchronously with Sidekiq.
EDIT: Unfortunately this didn't solved my thread problems completely =/

Kaizhi added a commit to centro/axlsx that referenced this pull request Feb 11, 2019
Kaizhi added a commit to centro/axlsx that referenced this pull request Feb 11, 2019
@loybert
Copy link

loybert commented Mar 8, 2019

@marshall-lee do you mind applying a rebase on the current master-branch to trigger a fresh travis-ci build?l

@loybert loybert mentioned this pull request Mar 8, 2019
This PR aims to fix several issues with Relationship cache:

1) It's not threadsafe, so I propose to use a TLS variable for this.
2) Memory obtained by cache remains non-freed before the next run of `serialize`. I think it should be freed immediately.
3) Memory should be freed in `ensure` block to prevent memory bloating in case of exception.

*There are only two hard things in Computer Science: cache invalidation and naming things.*
@marshall-lee
Copy link
Author

@randym @loybert I rebased the branch and added a couple of tests.

@marshall-lee
Copy link
Author

I also rewrote the cache to use the hash table instead of array. And also there's no need to store relationship instances — storing just ids is enough.

Also cacle only ids, not entire instances.
@loybert
Copy link

loybert commented Mar 11, 2019

@marshall-lee awesome! thanks for the fast feedback
@randym anything missing from your side?

@mtoneil
Copy link

mtoneil commented Jul 4, 2019

This PR fixes the thread safety issues we've had with the gem. Hoping this one can be merged soon!

@marshall-lee
Copy link
Author

ping @randym

@delphaber
Copy link

@marshall-lee thank you! :)

@noniq
Copy link
Collaborator

noniq commented Dec 15, 2019

@marshall-lee Thanks a lot for working on this! Would you like to recreate this pull request in https://github.com/caxlsx/caxlsx/ ? I think this is an important fix and we should definitively get this merged.

@noniq noniq added the Done in caxlsx This has already been solved in the caxlsx fork. label Dec 15, 2019
@noniq
Copy link
Collaborator

noniq commented Dec 15, 2019

Oh my, I just realized that this has already been done in caxlsx/caxlsx#10 🤦‍♂️ Sorry for the noise.

To minimize this kind of confusion in the future I created and new label “Done in caxlsx” that can be applied to prs / issues that have been included in caxlsx.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Done in caxlsx This has already been solved in the caxlsx fork.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants