Skip to content

WIP remove lastScope field and deprecated implementations from SimpleObservation#7273

Draft
shakuzen wants to merge 1 commit into
micrometer-metrics:mainfrom
shakuzen:bye-last-scope-hello-memory
Draft

WIP remove lastScope field and deprecated implementations from SimpleObservation#7273
shakuzen wants to merge 1 commit into
micrometer-metrics:mainfrom
shakuzen:bye-last-scope-hello-memory

Conversation

@shakuzen

@shakuzen shakuzen commented Mar 11, 2026

Copy link
Copy Markdown
Member

This should not be merged until main is 1.18.0 snapshots.

TODO: log warnings, update tests

This is a follow-up to #7255. With removing the lastScopes field on SimpleObservation, we avoid CPU cycles tracking info that is never used and we save memory per SimpleObservation instance.

JOL

We go from 40 bytes per instance to 32 bytes object overhead. See JOL output below. (with CompactObjectHeaders, it gets down to 24 bytes)

io.micrometer.observation.SimpleObservation object internals:
OFF  SZ                            TYPE DESCRIPTION                    VALUE
  0   8                                 (object header: mark)          N/A
  8   4                                 (object header: class)         N/A
 12   4             ObservationRegistry SimpleObservation.registry     N/A
 16   4                         Context SimpleObservation.context      N/A
 20   4           ObservationConvention SimpleObservation.convention   N/A
 24   4       Deque<ObservationHandler> SimpleObservation.handlers     N/A
 28   4   Collection<ObservationFilter> SimpleObservation.filters      N/A
Instance size: 32 bytes
Space losses: 0 bytes internal + 0 bytes external = 0 bytes total
Previous JOL output

io.micrometer.observation.SimpleObservation object internals:
OFF  SZ                            TYPE DESCRIPTION                    VALUE
  0   8                                 (object header: mark)          N/A
  8   4                                 (object header: class)         N/A
 12   4             ObservationRegistry SimpleObservation.registry     N/A
 16   4                         Context SimpleObservation.context      N/A
 20   4           ObservationConvention SimpleObservation.convention   N/A
 24   4       Deque<ObservationHandler> SimpleObservation.handlers     N/A
 28   4   Collection<ObservationFilter> SimpleObservation.filters      N/A
 32   4              Map<Thread, Scope> SimpleObservation.lastScope    N/A
 36   4                                 (object alignment gap)         
Instance size: 40 bytes
Space losses: 0 bytes internal + 4 bytes external = 4 bytes total

Benchmarks

We see allocation savings of 72 bytes per operation (explained by the object layout difference above and one less ConcurrentHashMap being instantiated). Note that is irrespective of the number of key-values used, so it will be a higher percent savings for Observations with less key-values.

This PR

ObservationBenchmark.observation                          avgt    2     96.621           ns/op
ObservationBenchmark.observation:gc.alloc.rate.norm       avgt    2    672.000            B/op

1.17.0-M3

ObservationBenchmark.observation                          avgt    2     96.910           ns/op
ObservationBenchmark.observation:gc.alloc.rate.norm       avgt    2    744.000            B/op

@shakuzen shakuzen added this to the 1.18.x milestone Mar 11, 2026
@shakuzen shakuzen added blocked An issue that's blocked on an external project change module: micrometer-observation labels Mar 11, 2026
@shakuzen shakuzen force-pushed the bye-last-scope-hello-memory branch 2 times, most recently from 06d0f8a to e690f6b Compare March 16, 2026 10:37
@shakuzen shakuzen force-pushed the bye-last-scope-hello-memory branch from e690f6b to 82edf76 Compare March 17, 2026 11:29
@shakuzen shakuzen added performance Issues related to general performance enhancement A general enhancement labels Mar 17, 2026
@shakuzen shakuzen removed the blocked An issue that's blocked on an external project change label Jun 11, 2026
@shakuzen shakuzen force-pushed the bye-last-scope-hello-memory branch from 82edf76 to 11fe5d2 Compare June 11, 2026 05:04
@shakuzen shakuzen modified the milestones: 1.18.x, 1.18.0-M1 Jun 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement A general enhancement module: micrometer-observation performance Issues related to general performance

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant