Closed maisem closed 5 months ago
Happy to send a PR for that, or someone can use the patch above and incorporate it. The CONTRIBUTING.md doesn't provide any guidance wrt CLAs so not sure what the process is here.
@maisem I'll take a look at it this weekend.
@maisem please see the devel branch
neat! Thanks, I'll try it out
@maisem Maybe it would be a better idea to use a constructor after all, what do you think?
func NewTable[V any]() *Table[V] {
return &Table[V]{
rootV4: newNode[V](),
rootV6: newNode[V](),
}
}
+1 for constructor with remove sync.Once
I personally prefer being able to use zero values as they go well when embedded into structs, but not a strong preference.
Relatedly, maybe Table could also clarify that it is safe for concurrent readers but not for concurrent readers and writers?
@maisem @mieczkowski may be it's a stupid idea, but see my new try to keep the zero value feature and still save cpu cycles under heavy load. See also the worstcase_test.go
file, in my cpu profiles no extra cycles shows up during heavy load.
Comments welcome!
You may want to consider using a isInitialized atomic.Bool
I think. Race detector might be unhappy otherwise
hmm, but then I can also stay with sync.Once
My next suggestion is using t.init
with sync.Once
, but for time critical lookups and for Delete()
I just test if
*rootNode == nil
followed by an empty return. See the next commits in the devel branch.
The Table struct has a sync.Once, which when tested under sufficient load shows up in CPU profiles.
As the implementation isn't really thread safe anyways, can this be changed to a bool instead?