Skip to content

tsdb [PERF]: move lastHistogramValue/lastFloatHistogramValue from memSeries to appenders#18515

Draft
krajorama wants to merge 3 commits intomainfrom
krajo/reduce-memseries-size
Draft

tsdb [PERF]: move lastHistogramValue/lastFloatHistogramValue from memSeries to appenders#18515
krajorama wants to merge 3 commits intomainfrom
krajo/reduce-memseries-size

Conversation

@krajorama
Copy link
Copy Markdown
Member

Summary

  • Remove lastHistogramValue *histogram.Histogram and lastFloatHistogramValue *histogram.FloatHistogram from memSeries, reducing its size by two pointer fields (16 bytes on 64-bit).
  • Add lastValue to HistogramAppender and FloatHistogramAppender (set on every appendHistogram/appendFloatHistogram call), with LastHistogram()/SetLastHistogram() and LastFloatHistogram()/SetLastFloatHistogram() accessors.
  • All call sites updated to type-assert on series.app; a new isHistogramStale() helper on memSeries de-duplicates the four stale-check locations.
  • The chunkSnapshotRecord WAL format is unchanged; snapshot load now restores appender state via the new setters.
[PERF] tsdb: reduce memSeries size by moving histogram last-value pointers into the chunk appenders.

Signed-off-by: György Krajcsovits [email protected]
Coded with Claude Sonnet 4.6.

krajorama and others added 3 commits April 13, 2026 11:52
…to appenders

Store the last appended histogram and float histogram in the
HistogramAppender and FloatHistogramAppender respectively, instead of
keeping redundant pointers in memSeries.

HistogramAppender gains LastHistogram()/SetLastHistogram() and
FloatHistogramAppender gains LastFloatHistogram()/SetLastFloatHistogram().
All callers in head_append.go, head.go, head_read.go and head_wal.go are
updated to type-assert on series.app and call the new accessors.  The
chunkSnapshotRecord fields are left unchanged (WAL on-disk format must not
change); snapshot load now initialises the appender from the snapshot record
via the new setters.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Signed-off-by: György Krajcsovits <[email protected]>
…astValue into appenders

Add two methods to the chunkenc.Appender interface:
- IsStaleLastValue() bool — replaces per-type stale checks scattered across
  head.go, head_read.go, head_append.go and head_wal.go.
- IsEqual(v float64, h *histogram.Histogram, fh *histogram.FloatHistogram) bool —
  replaces type assertions in appendableHistogram and appendableFloatHistogram.

xorAppender and xor2Appender implement IsStaleLastValue using the existing a.v
field (the last appended float), making it the canonical storage for the last
float value within the appender. HistogramAppender and FloatHistogramAppender
use their existing lastValue fields.

All callers are updated: the five separate stale checks in head.go,
head_read.go, head_append.go and head_wal.go collapse to isStaleLastValue()
calls; the duplicate-detection type assertions in appendableHistogram and
appendableFloatHistogram are replaced with IsEqual; and stale-transition
tracking in commitHistograms, commitFloatHistograms and WAL replay becomes a
single IsStaleLastValue() call per block. The isHistogramStale helper is
removed.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Signed-off-by: György Krajcsovits <[email protected]>
…ppender; remove memSeries.lastValue

Replace the two helper methods IsStaleLastValue() and IsEqual() on the
chunkenc.Appender interface with a single LastValue() method that returns
(v float64, h *histogram.Histogram, fh *histogram.FloatHistogram).

This lets callers inspect the last appended value without a type switch
and without maintaining a separate copy of the last float value in
memSeries. The field s.lastValue float64 is removed from memSeries as a
result.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Signed-off-by: György Krajcsovits <[email protected]>
@krajorama
Copy link
Copy Markdown
Member Author

/prombench main

@prombot
Copy link
Copy Markdown
Contributor

prombot commented Apr 13, 2026

⏱️ Welcome to Prometheus Benchmarking Tool. ⏱️

Compared versions: PR-18515 and main

After the successful deployment (check status here), the benchmarking results can be viewed at:

Available Commands:

  • To restart benchmark: /prombench restart main
  • To stop benchmark: /prombench cancel
  • To print help: /prombench help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants