go tdigest: only create a newLocalRNG if one is not provided by options
Allocating and seeding rand objects can be a surprisingly expensive operation. Especially if the user is already re-using RNGs, or needs to generate their own for whatever reason, this extra setup can be a lot of overhead for an object that does not get used.
- Id
- 428259572af62bcb45505af43359283c95524c65
- Author
- Zach Dylag
- Commit time
- 2022-10-07T13:47:57-07:00
Modified tdigest.go
tdigest := &TDigest{
compression: 100,
count: 0,
- rng: newLocalRNG(1),
}
for _, option := range options {
if err != nil {
return nil, err
}
+ }
+
+ if tdigest.rng == nil {
+ tdigest.rng = newLocalRNG(1)
}
return tdigest, nil