Repository navigation
refactor(model): refactor TimelineBuilder revisions and events to lightweight types - #941
Merged
Merged
Conversation
…htweight types Store events and revisions in TimelineBuilder as lightweight value-type structs (pendingEvent and pendingRevision) rather than full Protobuf heap pointers. This reduces memory allocations, GC overhead, and decouples timeline sorting from log accumulator queries. - Define pendingEvent and pendingRevision in pkg/model/khifile/v6. - Convert mutations in TimelineChangeSet.Flush to lightweight pending types. - Add TimelineBuilder.FindOldestTime to eliminate slices.Clone and external log lookups during sorting. - Defer Protobuf conversion and chronological sorting to ToProto during serialization.
kyasbal
requested review from
K53,
RyuSA,
jyane,
kkuchima and
renamoo
as code owners
September 2, 2026 05:38
Contributor
There was a problem hiding this comment.
Code Review
This pull request refactors the timeline accumulation logic to use lightweight, value-type structs (such as pendingEvent and pendingRevision) instead of protobuf heap pointers, reducing memory footprint and GC overhead. The review feedback suggests utilizing generated protobuf getters (GetTs() and GetId()) to simplify nil-checking logic and pre-allocating the annotations slice to optimize memory allocations.
…melineChangeSet.Flush
… TimelineChangeSet
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
In
khifilev6,TimelineBuilderpreviously accumulated events as[]*pb.Eventand revisions as[]*pb.Revision. Each mutation converted data into heap-allocated Protobuf message structs and pointers (*uint32,*timestamppb.Timestamp, etc.), leading to excessive memory allocations, GC pressure, and coupling withLogAccumulatorduring timeline sorting (timeline_sorter.go).This change refactors
TimelineBuilderto accumulate lightweight value-type structs:Lightweight Value Types (
pkg/model/khifile/v6/timeline_builder.go):pendingEvent: HoldsTimestamp time.Time(copied from the associated log) andLogID uint32in a contiguous slice[]pendingEvent.pendingRevision: Holds primitive IDs (uint32),time.Time, and unexportedpendingFieldAnnotationstructs in a contiguous slice[]pendingRevision.internPoolfield fromTimelineBuilder.Decoupled Sorting via
TimelineBuilder.FindOldestTime():slices.Cloneand queries toregistry.GetLogintimeline_sorter.go.Deferred Protobuf Serialization:
TimelineBuilder.ToProto()delegates to modular helper functions (convertEventsToProtoLocked,convertRevisionsToProtoLocked, etc.).Updated Accumulation and Tests:
TimelineChangeSet.Flush: Converts staging events and revisions to lightweight pending types.timeline_builder_test.go,timeline_serializer_test.go,timeline_sorter_test.go, andbuilder_test.goto match the new internal signatures and verified event sorting and oldest time detection.Test Plan
make pre-commitmake lint-goandmake test-go