Submit a batch of code optimizations#72
Merged
hao022 merged 7 commits intoccfos:mainfrom Nov 25, 2025
Merged
Conversation
Introduce BuildCSSToContainerID so we can reuse an existing container map, and switch the OOM tracer to call it instead of making a second lookup. Signed-off-by: Hao Li <[email protected]>
Store victim container ID in a local variable before updating containerOOMCounter. This avoids repeating the cts[...] lookup and makes the code easier to read. Signed-off-by: Hao Li <[email protected]>
The trigger/victim formatting logic duplicated the same fallback, hostname, and counter code. Move this into helper functions so the main event loop reads linearly Signed-off-by: Hao Li <[email protected]>
- Add pod.BuildCSSToContainer to build css->*Container maps for a given subsystem. - Use GetNormalContainers + BuildCSSToContainer in startRunqlatTracerWork so the CSS mapping is built once per loop instead of per-entry GetContainerByCSS calls. - Keeps the runqlat hot path simple while avoiding repeated full container scans. Signed-off-by: Hao Li <[email protected]>
GetContainerByCSS was called for every perf event, which repeatedly traversed all containers. Keep a css->container cache with a short TTL, refresh it on expiry, and re-check on misses. Preserve the original tongue-in-cheek comment about ignoring non-container events so the context remains. Signed-off-by: Hao Li <[email protected]>
Go strings are immutable, and any operation that appears to modify a string, such as strings.Trim, actually creates a new string. When we convert a byte slice (buf[:]) to a string, and then trim it, we are creating an intermediate string, which results in extra memory allocation and copying. Frequent allocations from repeated string conversions and trimming can increase the load on the Go runtime's garbage collector, which can impact overall performance especially when there are lots of events. Multiple tracers converted fixed-size C buffers into Go strings via string()+strings.Trim(…x00), which causes two allocations per event. Introduce internal/utils/bytesutil.CString to stop at the first zero byte, then switch all comm/name parsing (OOM, memory reclaim, softirq/softlockup, dropwatch, netrecvlat, netdev txqueue timeout, hungtask, perf parser, iotracing, and container CSS helpers) to call it. This removes the repeated trim boilerplate and cuts allocations in these hot paths. Signed-off-by: Hao Li <[email protected]>
Expose BuildCSSToContainer to map css addresses directly to container pointers. Runqlat now builds its cpu css cache via the helper using GetNormalContainers. This removes repeated manual css map construction and redundant GetContainerByCSS scans. Signed-off-by: Hao Li <[email protected]>
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.
There were no functional changes; only code efficiency was optimized and some logic was simplified.