aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Czygan <martin.czygan@gmail.com>2021-07-05 22:49:57 +0200
committerMartin Czygan <martin.czygan@gmail.com>2021-07-05 22:49:57 +0200
commit24090f8c65c82942272654356117ee0825d60523 (patch)
treee2af11c0c0a6d165a62e6cf1a1a8c57f0a10764e
parent9794996b3bda583ffd1d59b2f831518210033be3 (diff)
downloadrefcat-24090f8c65c82942272654356117ee0825d60523.tar.gz
refcat-24090f8c65c82942272654356117ee0825d60523.zip
reduce: reduce allocations
-rw-r--r--skate/reduce.go29
1 files changed, 24 insertions, 5 deletions
diff --git a/skate/reduce.go b/skate/reduce.go
index ff836e8..a7a6d8a 100644
--- a/skate/reduce.go
+++ b/skate/reduce.go
@@ -10,8 +10,11 @@
// the readers (and string groups): release, ref, ref-as-release, open library,
// wikipedia, ...
//
-// TODO: [ ] pass release stage through all match types
-// TODO: [ ] switch to faster logging, e.g. zerolog, https://github.com/rs/zerolog#benchmarks
+// TODO:
+// * [ ] pass release stage through all match types
+// * [ ] switch to faster logging, e.g. zerolog, https://github.com/rs/zerolog#benchmarks
+// * [ ] batch, parallelize
+// * [ ] unify flags to "-a", "-b"
package skate
import (
@@ -35,6 +38,20 @@ var brefPool = sync.Pool{
},
}
+var releasePool = sync.Pool{
+ New: func() interface{} {
+ var r Release
+ return &r
+ },
+}
+
+var refPool = sync.Pool{
+ New: func() interface{} {
+ var r Ref
+ return &r
+ },
+}
+
// groupLogf logs a message alongsize a serialized group for debugging.
func groupLogf(g *zipkey.Group, s string, vs ...interface{}) {
log.Printf(s, vs...)
@@ -56,10 +73,12 @@ func ZippyExact(releases, refs io.Reader, matchResult MatchResult, w io.Writer)
log.Printf("processed %v groups", i)
}
var (
- target *Release
- ref *Ref
+ target = releasePool.Get().(*Release)
+ ref = refPool.Get().(*Ref)
err error
)
+ defer releasePool.Put(target)
+ defer refPool.Put(ref)
if len(g.G0) == 0 || len(g.G1) == 0 {
return nil
}
@@ -73,6 +92,7 @@ func ZippyExact(releases, refs io.Reader, matchResult MatchResult, w io.Writer)
continue
}
bref = brefPool.Get().(BiblioRef)
+ defer brefPool.Put(bref)
bref.Reset()
bref.SourceReleaseIdent = ref.ReleaseIdent
bref.SourceWorkIdent = ref.WorkIdent
@@ -88,7 +108,6 @@ func ZippyExact(releases, refs io.Reader, matchResult MatchResult, w io.Writer)
if err := enc.Encode(bref); err != nil {
return err
}
- brefPool.Put(bref)
}
return nil
}