question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Pain point: a way to minify serial names automatically

See original GitHub issue

What is your use-case and why do you need this feature? By default, kx.serialization uses full names for enum items and polymorphic types, for field names. There are two cons I see:

  1. The decoding time is slower because there is a need to compare long strings.
  2. The size of serialized content is huge.

So in my protocol I have SerialNames specified almost everywhere to make names as compact as possible (you can take sample repo from #907):

@Serializable
enum class PaintType {
  @SerialName("a")
  DRAW,

  @SerialName("b")
  FILL,
}
@Serializable
sealed class ImageId {

  @Serializable
  @SerialName("a")
  data class BufferedImageId(
    @SerialName("a")
    val identityHash: Int,
    @SerialName("b")
    val stateHash: Int
  ) : ImageId()

  @Serializable
  @SerialName("b")
  data class PVolatileImageId(
    @SerialName("a")
    val id: Long
  ) : ImageId()
// ...

It’s not convenient to support such code. I can barely see signature of a class. We even have a special test which checks that all serial names in any context form alphabet.

Describe the solution you’d like

I believe a feature to minify serial names automatically should be available.

A parameter for @Serializable annotation is a good temporary solution. Setting a mask for FQNs of classes that should be minified in Gradle script is even cooler.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
pdvriezecommented, Feb 1, 2021

@SerVB Sequential serialization is where you don’t write any names at all. You just write the minimum needed (for polymorphism you still need a discriminator, unfortunately). Of course such serialization is not particularly robust (but neither is using arbitrary letters as names). Formats such as ProtoBuf, Json and XML are designed to be robust and allow for backwards (and forwards) compatibility. Btw. in terms of file/message size, repeating names compress very very well - the main issue would be parsing speed, but for something like that you would go to a binary format anyway.

2reactions
sandwwraithcommented, Jul 14, 2020

See also: #33

We do not plan to introduce this feature for now, mainly because of the philosophy “what you see in definition of class in Kotlin code is what you get in the JSON output”. Although minification is an interesting use-case for naming policies, why don’t use binary formats (cbor, protobuf) if one want to minimize output size?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Automagically Minify CSS and Javascript on Upload
First it takes all of your development files and concatenates them into a single file, then the concatenated file gets compressed and copied ......
Read more >
Website Pain Points Ultimate Guide for 2022 & How to Fix Them
With this ultimate guide on website pain points, you can finally tackle these issues, or find an interactive company who can assist you....
Read more >
Minifying JavaScript Files with Build Events - Paul Schaeflein
The target we've created shows a semi-colon separated list of items in the project that have the JavaScript build action. Looking good!
Read more >
How to Minify JavaScript — Recommended Tools and Methods
JavaScript has a library called UglifyJS to uglify code automatically. It improves performance and decreases the readability to make the code ...
Read more >
Customer Pain Points: Types, How to Identify and Address Them
After a series of conversations, you need to leave with the following deliverables. List of tasks. You can't address every single pain point, ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found