Skip to content

Cache allocatable types#12

Merged
fmstephe merged 4 commits intomasterfrom
cache-allocatable-types
Feb 9, 2025
Merged

Cache allocatable types#12
fmstephe merged 4 commits intomasterfrom
cache-allocatable-types

Conversation

@fmstephe
Copy link
Owner

@fmstephe fmstephe commented Feb 9, 2025

No description provided.

Previously we passed the type in via a generic parameter. Passing it in
as a struct allows us to build the reflect type and cache it outside of
the containsNoPointer() function.

The store itself will cache the results to this function call to avoid
calling it every time we allocate a type.
Previously every allocation would perform a check on whether the
allocation type contains pointers. This work is very slow and allocates
a remarkable amount of memory.

We introduce a cache which simply stores types which have been
successfully checked previously. This cache is protected by a read/write
lock - which does put another lock on the allocation path.
@fmstephe fmstephe force-pushed the cache-allocatable-types branch from e275904 to 3e4e1e5 Compare February 9, 2025 09:26
This struct is responsible for checking whether types contain pointers.
It caches acceptable types to avoid repeated, expensive, type checks.
There is only one file which contains all of the type checking code in
it.

We also add tests which directly test the pointerCheck type as well as
the containsNoPointers() function. We preserve the lower level function
tests because they are able to verify that the exact type failures we
expect are being found, and described in the error text.
@fmstephe fmstephe force-pushed the cache-allocatable-types branch from 3e4e1e5 to ff40120 Compare February 9, 2025 09:30
@fmstephe fmstephe merged commit f69ea92 into master Feb 9, 2025
1 check passed
@fmstephe fmstephe deleted the cache-allocatable-types branch February 9, 2025 09:31
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.

1 participant