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

Eliminate boxing of protocol types for serialization #2330

Merged
merged 5 commits into from
Sep 27, 2024

Conversation

JakeWharton
Copy link
Collaborator

We still have a few cases of use within a Zipline interface that causes it, but those are rarely invoked (protocol mismatch handlers).

#1040


  • CHANGELOG.md's "Unreleased" section has been updated, if applicable.

We still have a few cases of use within a Zipline interface that causes it, but those are rarely invoked (protocol mismatch handlers).
Comment on lines +37 to +39
Note: The types in this file are written in a careful way such that their serializable properties
are scalars which can be serialized directly rather than using value classes are boxed within the
generated kotlinx.serialization code.
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't love this, but kotlinx.serialization boxes every value class instance on both serialization and deserialization paths, and this avoids that without changing the public API (aside from invoke vs constructor).

public abstract fun removeWidget(id: Id)

@RedwoodCodegenApi
public val childrenVisitor: ProtocolWidget.ChildrenVisitor = if (synthesizeSubtreeRemoval) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Allocate only once, rather than once per children wrapper.

removedIds: List<Id> = listOf(),
removedIds: List<Id>,
Copy link
Collaborator Author

@JakeWharton JakeWharton Sep 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This caused boxing of the Id and ChildrenTag in JS if the caller omitted this last argument and relied on the default.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a way we can validate boxing doesn't occur in a test case? Or is it only possible when inspecting the generated code?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll think about it. You definitely can see the boxing in a full compiler plugin, and maybe in FIR only. Probably also as a lint check.

Filed #2336

Copy link
Member

@colinrtwhite colinrtwhite left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice

This deduplicates things, but it also prevents an initialization cycle which was causing the value to always be false.
@JakeWharton JakeWharton enabled auto-merge (squash) September 26, 2024 19:53
@JakeWharton JakeWharton merged commit ebdc0b1 into trunk Sep 27, 2024
11 checks passed
@JakeWharton JakeWharton deleted the jw.unboxing.2024-09-25 branch September 27, 2024 15:18
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.

2 participants