[Framework] Improve saferTrie node's value#71
Conversation
b03e259 to
49b4f72
Compare
…functions declarations
c8147c0 to
e168a5f
Compare
There was a problem hiding this comment.
I'm not convinced that the memory improvement is this critical that this change is required.
But regardless, since you anyway use a slice string in CanaryTarget, isn't it better to only have a single, static struct?
something like:
type FunctionTarget struct {
mainFunction string
canaryFunction string
}Then, you don't need the interface at all.
You can even define the as string pointers and might save even more memory.
rokatyy
left a comment
There was a problem hiding this comment.
Very nice! I'm actually on the side of using interface, I think it provides more flexibility and allows to hide all logic under the hood. Just one comment, other than that lgtm
| if pathFunctionNames.Contains(function) { | ||
| // If the function already exists at this path, skip adding it to prevent duplicates | ||
| return nil | ||
| } | ||
|
|
There was a problem hiding this comment.
not needed anymore, part of Add anyway
There was a problem hiding this comment.
Done here- CR comment- rephrase comments
Thanks for the feedback, @TomerShor
I hope this explanation clarifies my approach — I believe these changes are beneficial, and I’d appreciate your consideration in proceeding with the proposed changes. |
TomerShor
left a comment
There was a problem hiding this comment.
Looks good and approved, but with an open question
pkg/ingresscache/safetrie.go
Outdated
| type SingleTarget struct { | ||
| functionName string | ||
| } |
There was a problem hiding this comment.
This can also be a wrapper for a string
| type SingleTarget struct { | |
| functionName string | |
| } | |
| type SingleTarget string |
If we're talking about optimization, what is the difference between the two?
There was a problem hiding this comment.
Agreed, fixed here - CR comment-change singleTarget from struct to a string wrapper
Motivation
Described in the Jira - https://iguazio.atlassian.net/browse/NUC-486
Root Cause
Memory Layout:
Performance Improvements:
Description
This PR introduces a memory-optimized approach for storing values in the
safeTrie.Instead of using
[]stringto represent function names, this change replaces it with a lightweight struct-based abstraction:FunctionTarget.It includes two concrete implementations:
SingleFunctionTarget– holds a single function nameCanaryFunctionTarget– holds exactly two function namesThe
FunctionTargetis propagated to the upper cache layer, and the related interfaces were renamed for clarity and consistency.Affected Areas
Since the only usage of the
FunctionTargetresides inside the cache, there are no affected areas.Testing
Changes Made
FunctionTargetinterface withSingleFunctionTargetandCanaryFunctionTargetimplementationssafeTrieand cache layers to support and propagate the new interfaceFunctionTargetdesignAdditional Notes
FunctionTargetabstraction outside the cache (e.g., surfacing it in the cache interface) is left open for further discussion in the code review.