From 6826a8176c0c9b0647fc34f7f1f1e6448277ff3f Mon Sep 17 00:00:00 2001 From: Pierre Krieger Date: Fri, 7 Sep 2018 12:30:21 +0200 Subject: [PATCH 1/2] Use BufReader and BufWriter --- substrate/network-libp2p/src/topology.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/substrate/network-libp2p/src/topology.rs b/substrate/network-libp2p/src/topology.rs index 8ac0acd858031..f11c9de5dbcc9 100644 --- a/substrate/network-libp2p/src/topology.rs +++ b/substrate/network-libp2p/src/topology.rs @@ -19,7 +19,7 @@ use parking_lot::Mutex; use libp2p::{Multiaddr, PeerId}; use serde_json; use std::{cmp, fs}; -use std::io::{Read, Cursor, Error as IoError, ErrorKind as IoErrorKind, Write}; +use std::io::{Read, Cursor, Error as IoError, ErrorKind as IoErrorKind, Write, BufReader, BufWriter}; use std::path::{Path, PathBuf}; use std::time::{Duration, Instant, SystemTime}; @@ -101,7 +101,7 @@ impl NetTopology { }; let file = fs::File::create(path)?; - serialize(file, &self.store) + serialize(BufWriter::with_capacity(1024 * 1024, file), &self.store) } /// Perform a cleanup pass, removing all obsolete addresses and peers. @@ -497,7 +497,7 @@ fn try_load(path: impl AsRef) -> FnvHashMap { } let mut file = match fs::File::open(path) { - Ok(f) => f, + Ok(f) => BufReader::with_capacity(1024 * 1024, f), Err(err) => { warn!(target: "sub-libp2p", "Failed to open peer storage file: {:?}", err); info!(target: "sub-libp2p", "Deleting peer storage file {:?}", path); From e602f2c7f782cc203184da7771dff2f751652cc2 Mon Sep 17 00:00:00 2001 From: Pierre Krieger Date: Fri, 7 Sep 2018 16:12:10 +0200 Subject: [PATCH 2/2] Add TODOs --- substrate/network-libp2p/src/topology.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/substrate/network-libp2p/src/topology.rs b/substrate/network-libp2p/src/topology.rs index f11c9de5dbcc9..dc7a32cad9c06 100644 --- a/substrate/network-libp2p/src/topology.rs +++ b/substrate/network-libp2p/src/topology.rs @@ -101,6 +101,7 @@ impl NetTopology { }; let file = fs::File::create(path)?; + // TODO: the capacity of the BufWriter is kind of arbitrary ; decide better serialize(BufWriter::with_capacity(1024 * 1024, file), &self.store) } @@ -497,6 +498,7 @@ fn try_load(path: impl AsRef) -> FnvHashMap { } let mut file = match fs::File::open(path) { + // TODO: the capacity of the BufReader is kind of arbitrary ; decide better Ok(f) => BufReader::with_capacity(1024 * 1024, f), Err(err) => { warn!(target: "sub-libp2p", "Failed to open peer storage file: {:?}", err);