Skip to content

perf(core): optimize orderedMapNode reader access and release raw logs after ingestion - #931

Merged
kyasbal merged 2 commits into
GoogleCloudPlatform:mainfrom
kyasbal:push-vtrsknswuonq
Sep 1, 2026
Merged

kyasbal merged 2 commits into
GoogleCloudPlatform:mainfrom
kyasbal:push-vtrsknswuonq

Conversation

@kyasbal

@kyasbal kyasbal commented Sep 1, 2026

Copy link
Copy Markdown
Member

Summary

This PR addresses memory consumption during log ingestion in KHI by optimizing two key areas:

  1. Unwrap orderedMapNode: orderedMapNode was previously converting map entries to a full array on every call to Children(), causing massive allocation overhead (~4.49 GB) during structured path traversal. An Unwrap() Node method was introduced, allowing NodeReader to directly traverse the underlying map node.
  2. Release raw logs after ingestion: Log ingester tasks retained full slices of []*log.Log in the task DAG for downstream timeline mapper tasks. By updating log ingester tasks to return taskid.TaskReference[struct{}] and releasing raw logs immediately upon ingestion, we allow the Go GC to reclaim memory during DAG execution.

Profiling & Benchmark Comparison

Benchmark on 5 hours of GKE cluster logs (approx. 100k log entries):

Metric Before (Baseline) After (This PR) Reduction
Total Cumulative Allocations (alloc_space) 8,567.15 MB (~8.57 GB) 4,945.85 MB (~4.95 GB) -3,621.30 MB (-42.3%)
orderedMapNode.Children Allocations 4,493.59 MB 0 MB -100% (Eliminated)
Final Retained Memory (inuse_space) 430.58 MB 421.47 MB -9.11 MB

Verification

  • make test-go passed cleanly
  • make lint-go passed with 0 issues
  • make pre-commit passed

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request introduces CPU and memory profiling support, refactors log ingester tasks to return struct{} instead of []*log.Log to avoid redundant memory allocation, and implements a dynamic re-splitting mechanism in TimePartitioningProgressReportableLogFetcher to optimize concurrent log fetching. The review feedback suggests removing the unused cancelChild field and its redundant assignment in dynamicPartitionTask to clean up dead code.

@kyasbal

kyasbal commented Sep 1, 2026

Copy link
Copy Markdown
Member Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request introduces CPU and memory profiling capabilities via new debug parameters, and refactors log ingester tasks to return struct{} instead of []*log.Log to optimize memory usage. Additionally, it adds an Unwrap method to orderedMapNode to allow direct field lookups on wrapped nodes. Feedback on the changes highlights a potential nil pointer dereference panic in pkg/common/structured/reader.go if currentNode becomes nil during path traversal, and suggests adding a defensive nil check.

Comment thread pkg/common/structured/reader.go Resolved
@kyasbal kyasbal added the type:bug Something isn't working as expected label Sep 1, 2026
@kyasbal
kyasbal merged commit c9db3bc into GoogleCloudPlatform:main Sep 1, 2026
16 checks passed
@kyasbal
kyasbal deleted the push-vtrsknswuonq branch September 1, 2026 03:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type:bug Something isn't working as expected

1 participant