Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions blockstm/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"runtime"
"sync"
"sync/atomic"

"golang.org/x/sys/cpu"
)

type TaskKind int
Expand Down Expand Up @@ -32,10 +34,15 @@ func (t *TxDependency) Swap(new []TxnIndex) []TxnIndex {
type Scheduler struct {
blockSize int

_ cpu.CacheLinePad

// An index that tracks the next transaction to try and execute.
executionIdx atomic.Uint64
// A similar index for tracking validation.
validationIdx atomic.Uint64

_ cpu.CacheLinePad
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we keep executionIdx and validationIdx in the same cache line, because each executor thread will read both anyway.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How did you determine that this yields any perf improvements? Can you attach your local benchmarks here?

Copy link
Contributor

@songgaoye songgaoye Jan 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we keep executionIdx and validationIdx in the same cache line, because each executor thread will read both anyway.

I don't think so. Executors read both executionIdx and validationIdx both indices, but they read and write different ones most of the time (executution workers increment executionIdx, validators bump validationIdx).
Keeping them in the same cache line means those writes will constantly invalidate each other’s cache line even though the fields track unrelated counters.
That false sharing is exactly what the padding was supposed to prevent.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we keep executionIdx and validationIdx in the same cache line, because each executor thread will read both anyway.

I don't think so. Executors read both executionIdx and validationIdx both indices, but they read and write different ones most of the time (executution workers increment executionIdx, validators bump validationIdx). Keeping them in the same cache line means those writes will constantly invalidate each other’s cache line even though the fields track unrelated counters. That false sharing is exactly what the padding was supposed to prevent.

I mean at the beginning of the loop, each executor will read both executionIdx and validationIdx to compare them for priority.


// Number of times validationIdx or executionIdx was decreased
decreaseCnt atomic.Uint64
// Number of ongoing validation and execution tasks
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ require (
go.yaml.in/yaml/v3 v3.0.4
golang.org/x/crypto v0.47.0
golang.org/x/sync v0.19.0
golang.org/x/sys v0.39.0
google.golang.org/genproto/googleapis/api v0.0.0-20251202230838-ff82c1b0f217
google.golang.org/grpc v1.78.0
google.golang.org/protobuf v1.36.11
Expand Down
Loading