Skip to content

Commit c620bf1

Browse files
authored
llo: perform an vss alloc at plugin initialization to avoid GC overhead (#187)
1 parent 1215d13 commit c620bf1

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

llo/plugin.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"errors"
66
"fmt"
7+
sync "sync"
78
"time"
89

910
"github.com/smartcontractkit/libocr/quorumhelper"
@@ -16,6 +17,17 @@ import (
1617
"github.com/smartcontractkit/libocr/offchainreporting2plus/ocr3types"
1718
)
1819

20+
var (
21+
// ballastAlloc is a byte slice initialized to 1GB to reduce CPU cycles spent in garbage collection.
22+
// The plugin's data source pipeline performs many small allocations, which can frequently trigger the GC
23+
// and increase CPU usage during the mark phase. The ballast allocation is virtually addressed and does not
24+
// consume physical memory unless accessed. Since the Go GC runs when the heap size doubles, this ensures
25+
// GC is only triggered when the heap grows to 2GB.
26+
ballastAlloc []byte
27+
ballastOnce sync.Once
28+
ballastSz int = 1e9 // 1GB
29+
)
30+
1931
// Additional limits so we can more effectively bound the size of observations
2032
// NOTE: These are hardcoded because these exact values are relied upon as a
2133
// property of coming to consensus, it's too dangerous to make these
@@ -261,6 +273,11 @@ func (f *PluginFactory) NewReportingPlugin(ctx context.Context, cfg ocr3types.Re
261273
return nil, ocr3types.ReportingPluginInfo{}, fmt.Errorf("NewReportingPlugin failed to create observation codec: %w", err)
262274
}
263275

276+
// Initialize the memory ballast
277+
ballastOnce.Do(func() {
278+
ballastAlloc = make([]byte, ballastSz)
279+
})
280+
264281
return &Plugin{
265282
f.Config,
266283
onchainConfig.PredecessorConfigDigest,

0 commit comments

Comments
 (0)