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

Lazy load UNIT_TYPE #580

Closed
orangy opened this issue Aug 20, 2022 · 2 comments
Closed

Lazy load UNIT_TYPE #580

orangy opened this issue Aug 20, 2022 · 2 comments
Milestone

Comments

@orangy
Copy link

orangy commented Aug 20, 2022

Use case
We often use ObjectMapper for just json parsing and not full object mapping. Initialization of KotlinAnnotationIntrospector currently causes a delay because of Kotlin Reflection loading. We would like to eliminate this delay until it is really needed.

Describe the solution you'd like
Replace

        val UNIT_TYPE: KType = Unit::class.createType()

with

        val UNIT_TYPE: KType by lazy { Unit::class.createType() }

Describe alternatives you've considered
Alternative would be avoiding creating UNIT_TYPE altogther and replacing single usage returnType == UNIT_TYPE with checking FQN since it is well-known.

@sarbyn
Copy link
Contributor

sarbyn commented Jan 16, 2023

We got some ANR on our Android App (mainly on old devices) related to this issue, during Dagger init.

The stack trace is the following:

main (runnable):tid=1 systid=26675 
       at kotlin.reflect.jvm.internal.impl.serialization.deserialization.descriptors.DeserializedClassDescriptor$DeserializedClassTypeConstructor.getParameters(DeserializedClassDescriptor.kt:281)
       at kotlin.reflect.full.KClassifiers.createType(KClassifiers.kt:52)
       at kotlin.reflect.full.KClassifiers.createType$default(KClassifiers.java:43)
       at com.fasterxml.jackson.module.kotlin.KotlinAnnotationIntrospector.<clinit>(KotlinAnnotationIntrospector.kt:170)
       at com.fasterxml.jackson.module.kotlin.KotlinModule.setupModule(KotlinModule.kt:121)
       at com.fasterxml.jackson.databind.ObjectMapper.registerModule(ObjectMapper.java:853)
       [...]
       

Kotlin 1.5.31
Jackson 2.13.1

We will update kotlin, jackson to the latest versions and we will also use Dagger lazy inject, but I think it could be better to fix also on Jackson side. (I can do a Pull request if needed)

@cowtowncoder
Copy link
Member

Note: 2.13 branch is unlikely to get new patches so I would strongly recommend seeing whether 2.14(.1) might help here. And if you do that maybe add a note (I am not saying there is a fix just that sometimes newer versions do have relevant fixes).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants