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

Remove dynamic dispatch from (General)LazyBufferCache #93

Merged
merged 5 commits into from
Jan 3, 2024

Conversation

LilithHafner
Copy link
Member

@LilithHafner LilithHafner commented Jan 3, 2024

Checklist

  • Appropriate tests were added
  • Any code changes were done in a way that does not break public API
  • All documentation related to code changes were updated
  • The new code follows the
    contributor guidelines, in particular the SciML Style Guide and
    COLPRAC.
  • Any new documentation only uses public API

Additional context

Add any other context about the problem here.

sizemap::F
LazyBufferCache(f::F = identity) where {F <: Function} = new{F}(Dict(), f) # start with empty dict
end

# override the [] method
function Base.getindex(b::LazyBufferCache, u::T) where {T <: AbstractArray}
s = b.sizemap(size(u)) # required buffer size
buf = get!(b.bufs, (T, s)) do
get!(b.bufs, (T, s)) do
Copy link
Member

Choose a reason for hiding this comment

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

Does that change actually make a difference?

Copy link
Member Author

Choose a reason for hiding this comment

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

Not at all. That is just for stylistic consistency with the rest of the file.

@LilithHafner LilithHafner changed the title Remove dynamic dispatch from LazyBufferCache Remove dynamic dispatch from (General)LazyBufferCache Jan 3, 2024
may not be even measurable. The upside of `LazyBufferCache` is that the user does
not have to worry about potential issues with chunk sizes and such: `LazyBufferCache`
is much easier!
Note that `LazyBufferCache` is type-stable and contains no dynamic dispatch. This gives
Copy link
Member

Choose a reason for hiding this comment

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

doesn't it have an internal dynamic dispatch?

Copy link
Member Author

Choose a reason for hiding this comment

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

No, it's just a lookup from a Dict{Any, Any}, which is not type stable, but doesn't have dynamic dispatch either.

Verified via @btime indicating no allocations and via @profview being a happy color (dynamic dispatch is supposed to show up in red)

Pasted image 3

(In theory the correct way to verify is JET)

Copy link
Member

Choose a reason for hiding this comment

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

wow that's pretty incredible. Julia used to not be able to omit that.

@ChrisRackauckas ChrisRackauckas merged commit 6c83dde into SciML:master Jan 3, 2024
10 of 11 checks passed
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