Skip to content

Avoid redundant unboxing & boxing for number adapters - #3175

Merged
eamonnmcmanus merged 1 commit into
google:mainfrom
Marcono1234:marcono1234/number-adapters-reduce-unboxing
Nov 16, 2026
Merged

eamonnmcmanus merged 1 commit into
google:mainfrom
Marcono1234:marcono1234/number-adapters-reduce-unboxing

Conversation

@Marcono1234

Copy link
Copy Markdown
Contributor

Purpose

Follow-up for #2998

Description

E.g. avoid Integer -> int -> Integer and instead keep using the existing Integer object.

The behavior remains the same; it still calls value(Number).

I have not measured the performance difference of this, maybe the JVM can optimize this code pattern already well (but only if the code is JIT compiled?) and this change is not needed.

Feel free to close this if you don't think it is useful.

Side note: I have not applied this to the Long and Double which currently call JsonWriter#value(long) and #value(double). The redundant boxing would only occur if the runtime type there is JsonTreeWriter; for JsonWriter it might (?) be more efficient to directly call value(long) and value(double) (as done by the current code) instead of value(Number).

E.g. avoid `Integer -> int -> Integer` and instead keep using the
existing Integer object.

@eamonnmcmanus eamonnmcmanus left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks! This looks fine.

@eamonnmcmanus
eamonnmcmanus merged commit e67037d into google:main Nov 16, 2026
22 checks passed
@Marcono1234
Marcono1234 deleted the marcono1234/number-adapters-reduce-unboxing branch November 16, 2026 18:29
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