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

Allow disabling of conversion of cache data #122

Open
1 task done
phxql opened this issue Feb 17, 2020 · 11 comments
Open
1 task done

Allow disabling of conversion of cache data #122

phxql opened this issue Feb 17, 2020 · 11 comments
Assignees
Labels
type: enhancement New feature or request

Comments

@phxql
Copy link

phxql commented Feb 17, 2020

Task List

  • Steps to reproduce provided

Steps to Reproduce

  1. Write a method which returns a huge map and annotate it with @Cacheable
  2. Call that method
  3. Call it again

Expected Behaviour

2nd method call is at least as fast as 1st.

Actual Behaviour

2nd method call is a lot slower.

Environment Information

  • Operating System: Fedora 31
  • Micronaut Version: 1.3.0
  • JDK Version: AdoptJDK 11.0.6

Hi,

the DefaultSyncCache uses the conversion service to convert the stuff coming from the actual cache implementation. The DefaultConversionService contains some code which iterates over all the keys from map (because it implements Iterable) and tries to convert them. I'm not sure why it's doing this, but this caused a huge performance hit in our application. We're using the default in-memory caffeine cache.

We worked around by wrapping the huge map in an object which doesn't implement Iterable and now it's fast again.

@graemerocher
Copy link
Contributor

Should be checking if conversion is needed before attempting conversion

@jameskleeh jameskleeh self-assigned this Feb 18, 2020
@jameskleeh
Copy link
Contributor

@phxql So you understand the root of this behavior. When the map is stored in the cache, any information about its generics are lost. We don't know what the key type or value type of the map is. When we retrieve the map, it is converted to being a Map<String, String> (or whatever the return type is). What we can do is add an option to the @CacheConfig annotation to allow disabling of the conversion.

@jameskleeh jameskleeh changed the title Performance problems with DefaultSyncCache Allow disabling of conversion of cache data Mar 13, 2020
@alvarosanchez
Copy link
Member

What if we would allow to define key and value types ?

@phxql
Copy link
Author

phxql commented Mar 16, 2020

@phxql So you understand the root of this behavior. When the map is stored in the cache, any information about its generics are lost. We don't know what the key type or value type of the map is. When we retrieve the map, it is converted to being a Map<String, String> (or whatever the return type is). What we can do is add an option to the @CacheConfig annotation to allow disabling of the conversion.

Fine for me :)

@jameskleeh
Copy link
Contributor

This was implemented in the cache module

@jameskleeh jameskleeh transferred this issue from micronaut-projects/micronaut-core May 21, 2020
@graemerocher
Copy link
Contributor

@jameskleeh so can the issue be closed?

@stale
Copy link

stale bot commented Jul 21, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the status: stale label Jul 21, 2020
@alvarosanchez
Copy link
Member

@jameskleeh can this be closed?

@stale stale bot removed the status: stale label Jul 27, 2020
@alvarosanchez alvarosanchez added the type: enhancement New feature or request label Jul 27, 2020
@jameskleeh
Copy link
Contributor

@alvarosanchez
Copy link
Member

@jameskleeh were you done with it? If so, can you please create a PR? Otherwise, what is left?

@erkieh
Copy link

erkieh commented Dec 1, 2024

We got hit by this issue as well. Would be nice if this got merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants