use new stew helpers for assignment (#2172)

* bump libp2p (reduces libp2p gossip memory usage to ~1/3)
* use "generic" assign version
This commit is contained in:
Jacek Sieka 2020-12-16 09:37:22 +01:00 committed by GitHub
parent b0086c5d99
commit 7d5edb4353
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 15 additions and 45 deletions

View File

@ -9,6 +9,7 @@
import
std/[options, sequtils, tables, sets],
stew/assign2,
metrics, snappy, chronicles,
../ssz/[ssz_serialization, merkleization], ../beacon_chain_db, ../extras,
../spec/[

View File

@ -10,7 +10,7 @@
import
std/tables,
chronicles,
stew/results,
stew/[assign2, results],
../extras, ../time,
../spec/[crypto, datatypes, digest, helpers, signatures, state_transition],
./block_pools_types, ./chain_dag, ./quarantine

View File

@ -84,7 +84,6 @@ proc init*(T: type BeaconNode,
var
genesisState, checkpointState: ref BeaconState
genesisDepositsSnapshot: DepositContractSnapshot
checkpointBlock: SignedBeaconBlock
if conf.finalizedCheckpointState.isSome:

View File

@ -26,7 +26,7 @@
import
std/[macros, hashes, json, strutils, tables, typetraits],
stew/[byteutils], chronicles,
stew/[assign2, byteutils], chronicles,
json_serialization/types as jsonTypes,
../version, ../ssz/types as sszTypes, ./crypto, ./digest, ./presets
@ -833,34 +833,3 @@ static:
# Sanity checks - these types should be trivial enough to copy with memcpy
doAssert supportsCopyMem(Validator)
doAssert supportsCopyMem(Eth2Digest)
func assign*[T](tgt: var T, src: T) =
# The default `genericAssignAux` that gets generated for assignments in nim
# is ridiculously slow. When syncing, the application was spending 50%+ CPU
# time in it - `assign`, in the same test, doesn't even show in the perf trace
when supportsCopyMem(T):
when sizeof(src) <= sizeof(int):
tgt = src
else:
copyMem(addr tgt, unsafeAddr src, sizeof(tgt))
elif T is object|tuple:
for t, s in fields(tgt, src):
when supportsCopyMem(type s) and sizeof(s) <= sizeof(int) * 2:
t = s # Shortcut
else:
assign(t, s)
elif T is List|BitList:
assign(distinctBase tgt, distinctBase src)
elif T is seq:
tgt.setLen(src.len)
when supportsCopyMem(type(tgt[0])):
if tgt.len > 0:
copyMem(addr tgt[0], unsafeAddr src[0], sizeof(tgt[0]) * tgt.len)
else:
for i in 0..<tgt.len:
assign(tgt[i], src[i])
elif T is ref:
tgt = src
else:
unsupported T

View File

@ -10,7 +10,7 @@ import
std/[os, osproc, random, sequtils, streams, tables],
# Nimble packages
stew/[objects], stew/shims/macros,
stew/[assign2, objects, shims/macros],
chronos, metrics, json_rpc/[rpcserver, jsonmarshal],
chronicles,
json_serialization/std/[options, sets, net], serialization/errors,
@ -18,15 +18,15 @@ import
eth/[keys, async_utils], eth/p2p/discoveryv5/[protocol, enr],
# Local modules
spec/[datatypes, digest, crypto, helpers, network, signatures],
spec/state_transition,
conf, time, validator_pool,
attestation_pool, exit_pool, block_pools/[spec_cache, chain_dag, clearance],
eth2_network, keystore_management, beacon_node_common, beacon_node_types,
nimbus_binary_common,
eth1_monitor, version, ssz/merkleization,
attestation_aggregation, sync_manager, sszdump,
validator_slashing_protection
./spec/[
datatypes, digest, crypto, helpers, network, signatures, state_transition],
./conf, ./time, ./validator_pool,
./attestation_pool, ./exit_pool,
./block_pools/[spec_cache, chain_dag, clearance],
./eth2_network, ./keystore_management, ./beacon_node_common,
./beacon_node_types, ./nimbus_binary_common, ./eth1_monitor, ./version,
./ssz/merkleization, ./attestation_aggregation, ./sync_manager, ./sszdump,
./validator_slashing_protection
# Metrics for tracking attestation and beacon block loss
const delayBuckets = [-Inf, -4.0, -2.0, -1.0, -0.5, -0.1, -0.05,

View File

@ -8,7 +8,8 @@
{.used.}
import
options, sequtils, unittest,
std/[options, sequtils, unittest],
stew/assign2,
./testutil, ./testblockutil,
../beacon_chain/spec/[datatypes, digest, helpers, state_transition, presets],
../beacon_chain/[beacon_node_types, ssz],