Skip to content
Merged
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
4 changes: 2 additions & 2 deletions NBitcoin.Bench/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ This project use BenchmarkDotnet to measure performance of parts of NBitcoin imp

You can generate flamegraph to view with Perfview on Windows with the following command:
```powershell
dotnet run -c Release -- --runtimes netcoreapp2.1 --filter *GolombRiceFilters* --profiler ETW
dotnet run -c Release -- --runtimes net8.0 --filter *GolombRiceFilters* --profiler ETW
```

Where `GolombRiceFilters` is the name of the benchmark class you are insterested in.

For generating flamegraph on linux, see [this comment](https://github.com/MetacoSA/NBitcoin/pull/656#issuecomment-462927805).
For generating flamegraph on linux, see [this comment](https://github.com/MetacoSA/NBitcoin/pull/656#issuecomment-462927805).
15 changes: 12 additions & 3 deletions NBitcoin/ConcurrentChain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -289,12 +289,21 @@ private ChainedBlock SetTipNoLock(ChainedBlock block)
height--;
}
var fork = GetBlockNoLock(height);
foreach (var newBlock in block.EnumerateToGenesis()
.TakeWhile(c => c != fork))

// The while loop was manually changed from more idiomatic but slower:
// foreach (var newBlock in block.EnumerateToGenesis().TakeWhile(c => c != fork))
var newBlock = block;
while (newBlock != fork)
{
_BlocksById.AddOrReplace(newBlock.HashBlock, newBlock);
_BlocksById[newBlock.HashBlock] = newBlock;
AddOrReplaceBlocksByHeight(newBlock.Height, newBlock);

newBlock = newBlock.Previous;

if (newBlock is null)
break;
}

_Tip = block;
return fork;
}
Expand Down
Loading