Skip to content

Commit

Permalink
Optimize copying goroutine (#253)
Browse files Browse the repository at this point in the history
  • Loading branch information
outofforest authored Nov 29, 2024
1 parent f0188a8 commit 6e7f267
Showing 1 changed file with 24 additions and 24 deletions.
48 changes: 24 additions & 24 deletions db.go
Original file line number Diff line number Diff line change
Expand Up @@ -800,33 +800,33 @@ func (db *DB) copyNodes(
return err
}

for wr := req.WALRequest; wr != nil; wr = wr.Next {
walNode := waltypes.ProjectNode(db.config.State.Node(wr.NodeAddress))
var wrIndex uint16

for wrIndex < waltypes.BlobSize && wal.RecordType(walNode.Blob[wrIndex]) != wal.RecordEnd {
switch recordType := wal.RecordType(walNode.Blob[wrIndex]); recordType {
case wal.RecordSet1:
wrIndex += 10
case wal.RecordSet8:
wrIndex += 17
case wal.RecordSet32:
wrIndex += 41
case wal.RecordSet:
wrIndex += 9
wrIndex += *(*uint16)(unsafe.Pointer(&walNode.Blob[wrIndex])) + 2
case wal.RecordImmediateDeallocation, wal.RecordDelayedDeallocation:
wrIndex++
oldNodeAddress := *(*types.NodeAddress)(unsafe.Pointer(&walNode.Blob[wrIndex+8]))
newNodeAddress := *(*types.NodeAddress)(unsafe.Pointer(&walNode.Blob[wrIndex+16]))
wrIndex += 24
if processedCount&3 == mod {
for wr := req.WALRequest; wr != nil; wr = wr.Next {
walNode := waltypes.ProjectNode(db.config.State.Node(wr.NodeAddress))
var wrIndex uint16

for wrIndex < waltypes.BlobSize && wal.RecordType(walNode.Blob[wrIndex]) != wal.RecordEnd {
switch recordType := wal.RecordType(walNode.Blob[wrIndex]); recordType {
case wal.RecordSet1:
wrIndex += 10
case wal.RecordSet8:
wrIndex += 17
case wal.RecordSet32:
wrIndex += 41
case wal.RecordSet:
wrIndex += 9
wrIndex += *(*uint16)(unsafe.Pointer(&walNode.Blob[wrIndex])) + 2
case wal.RecordImmediateDeallocation, wal.RecordDelayedDeallocation:
wrIndex++
oldNodeAddress := *(*types.NodeAddress)(unsafe.Pointer(&walNode.Blob[wrIndex+8]))
newNodeAddress := *(*types.NodeAddress)(unsafe.Pointer(&walNode.Blob[wrIndex+16]))
wrIndex += 24

if uint64(newNodeAddress)&3 == mod {
copy(db.config.State.Bytes(newNodeAddress), db.config.State.Bytes(oldNodeAddress))
default:
fmt.Printf("%#v\n", walNode.Blob)
panic("=============")
}
default:
fmt.Printf("%#v\n", walNode.Blob)
panic("=============")
}
}
}
Expand Down

0 comments on commit 6e7f267

Please sign in to comment.