Skip to content

fix: optimization reducing memory allocations in MsgPackNullableDynamicSerializer#111

Merged
esensar merged 1 commit into
esensar:mainfrom
emtrane:feature/allocs
Mar 19, 2026
Merged

fix: optimization reducing memory allocations in MsgPackNullableDynamicSerializer#111
esensar merged 1 commit into
esensar:mainfrom
emtrane:feature/allocs

Conversation

@emtrane

@emtrane emtrane commented Mar 2, 2026

Copy link
Copy Markdown
Contributor

Replace when (value!!::class) with when (value) using is type checks in MsgPackNullableDynamicSerializer.serialize().

The previous implementation obtained a KClass via reflection on every call to match against class literals (e.g. Boolean::class), then performed redundant explicit casts (e.g. value as Boolean). Using is type checks instead compiles to simple instanceof checks with no reflection overhead or KClass allocations, and Kotlin smart casts eliminate the need for explicit casts.

Also flattens the previously nested when block for collection types into a single-level when expression for readability.

…icSerializer

Replace `when (value!!::class)` with `when (value)` using `is` type
checks in MsgPackNullableDynamicSerializer.serialize().

The previous implementation obtained a KClass via reflection on every
call to match against class literals (e.g. Boolean::class), then
performed redundant explicit casts (e.g. `value as Boolean`). Using
`is` type checks instead compiles to simple instanceof checks with no
reflection overhead or KClass allocations, and Kotlin smart casts
eliminate the need for explicit casts.

Also flattens the previously nested `when` block for collection types
into a single-level `when` expression for readability.
@esensar

esensar commented Mar 19, 2026

Copy link
Copy Markdown
Owner

Thanks, this makes sense!

@esensar
esensar merged commit 8cdf104 into esensar:main Mar 19, 2026
5 checks passed
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