GithubHelp home page GithubHelp logo

Comments (3)

k163377 avatar k163377 commented on August 17, 2024

I do not plan to implement setter support for value class at this time.
The reasons are as follows

  • Requires a very complex implementation.
  • It would degrade the overall performance of the kotlin-module as more reflection processing would be required.
  • Deserialization of Kotlin classes is generally done using constructors or factory functions, and there is theoretically no case where you must always use setters.

So, I am inlining a class that just contains an int (this improves performance and memory allocation in my application).

I would suggest benchmarking first.
For libraries using kotlin-reflect, performance will degrade if you use the value class.
Compared to using data class, for example, the throughput of deserialization is roughly 70% (see the benchmark results in the link).
https://github.com/FasterXML/jackson-module-kotlin/blob/2.18/docs/value-class-support.md#note-on-the-use-of-value-class

from jackson-module-kotlin.

Bixilon avatar Bixilon commented on August 17, 2024

Requires a very complex implementation.

Yes, agreed. I thought that is something already.

I would suggest benchmarking first.

My application does not use jackson heavily, it is more something for reading and writing settings (and a couple of other things). The main improvement comes from memory allocation, the color class is not mutable, and I already started replacing colors with int in a lot of places. The memory allocation goes down by 30-50 MB/s, it makes the gc almost sleep. In my case the jackson sacrifize would be totally worth it (even if it is slower by 10 times) to make the code quality go up and not use ints in the code. But I guess this is only true in my case and a lot of people would not want to take this.

Thanks for the answer, I need to find a different way (maybe use a color wrapper class or so for config files).

from jackson-module-kotlin.

k163377 avatar k163377 commented on August 17, 2024

The main improvement comes from memory allocation

Hmmm, if that is the case, it might be preferable not to use jackson-module-kotlin.
I haven't done a comparison, but as far as I know, this module uses more memory because it uses kotlin-reflect.

If you are looking for performance, since Jackson supports record classes, you might consider defining DTO as JvmRecord and not using kotlinModule.
Alternatively, kotlinx-serialization does not use reflection, which may also reduce runtime memory consumption (I believe value class is also supported).

from jackson-module-kotlin.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.