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

More alloc cache improvements #583

Merged
merged 6 commits into from
Jan 15, 2025
Merged

More alloc cache improvements #583

merged 6 commits into from
Jan 15, 2025

Conversation

maleadt
Copy link
Member

@maleadt maleadt commented Jan 10, 2025

  • cache DataRefs instead of arrays, which should be more lightweight and allow for more caching (eltype or dim mismatches)
  • lock more cache ops; I don't think the current implementation was safe

The manual refcount fiddling is a bit dangerous (it should be compatible with manual unsafe_free!s and the GC), but I think is correct. @pxl-th Maybe test with one of your apps using this? Ideally, first adapt your back-end to key on bufsize instead of dims and remove T.

@maleadt maleadt requested a review from pxl-th January 10, 2025 09:23
@pxl-th
Copy link
Member

pxl-th commented Jan 10, 2025

Thanks! I'll take a look at it this evening

src/host/alloc_cache.jl Outdated Show resolved Hide resolved
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Some suggestions could not be made:

  • src/host/abstractarray.jl
    • lines 65-66

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Some suggestions could not be made:

  • src/host/abstractarray.jl
    • lines 65-66

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Some suggestions could not be made:

  • src/host/abstractarray.jl
    • lines 65-66

Copy link
Member

@pxl-th pxl-th left a comment

Choose a reason for hiding this comment

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

Looks good. Left minor comment

"Invalidating inside `@cached` is not allowed."
)
for pool in values(cache.busy)
isempty(pool) || error("Cannot invalidate a cache that's in active use")
Copy link
Member

Choose a reason for hiding this comment

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

Maybe check that the pool is empty and that the cache is in use (reading ScopedValue). Otherwise, if an exception happens during @cached it will raise this in the cache finalizer.

Copy link
Member Author

Choose a reason for hiding this comment

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

That sounds questionable. Shouldn't @cached instead have a try/catch (well, the scope-less variety) that wipes the cache in the finally block, making sure the cache is always in a known-good state outside of the @cached block?

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Some suggestions could not be made:

  • src/host/abstractarray.jl
    • lines 65-66

@maleadt maleadt merged commit 9d8997c into master Jan 15, 2025
11 of 13 checks passed
@maleadt maleadt deleted the tb/alloc_cache branch January 15, 2025 08:51
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