From 6e7f2672962abe0de9cb26d32f6d8e6955282d80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wojciech=20Ma=C5=82ota-W=C3=B3jcik?= <59281144+outofforest@users.noreply.github.com> Date: Fri, 29 Nov 2024 18:51:40 +0100 Subject: [PATCH] Optimize copying goroutine (#253) --- db.go | 48 ++++++++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/db.go b/db.go index ca723bf..afcfe3c 100644 --- a/db.go +++ b/db.go @@ -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("=============") } } }