Skip to content

Commit 9c4c362

Browse files
HoOngEemergify[bot]
authored andcommitted
Make the sync module release memory aggressively
Shrink HashMaps and Vectors of downloaders and Verification queue to reduce the memory usage when syncing.
1 parent dc9a0cf commit 9c4c362

File tree

3 files changed

+11
-0
lines changed

3 files changed

+11
-0
lines changed

core/src/verification/queue/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,7 @@ impl<K: Kind> VerificationQueue<K> {
408408
*td -= score;
409409
}
410410
}
411+
processing.shrink_to_fit();
411412
processing.is_empty()
412413
}
413414

@@ -444,6 +445,7 @@ impl<K: Kind> VerificationQueue<K> {
444445
new_verified.push_back(output);
445446
}
446447
}
448+
processing.shrink_to_fit();
447449

448450
self.verification.sizes.verified.fetch_sub(removed_size, AtomicOrdering::SeqCst);
449451
*verified = new_verified;

sync/src/block/downloader/body.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ impl BodyDownloader {
6969
self.downloaded.insert(hash, body);
7070
}
7171
}
72+
self.downloading.shrink_to_fit();
7273
}
7374

7475
pub fn add_target(&mut self, header: &Header, parent: &Header) {
@@ -93,13 +94,17 @@ impl BodyDownloader {
9394
self.downloading.remove(hash);
9495
self.downloaded.remove(hash);
9596
}
97+
self.targets.shrink_to_fit();
98+
self.downloading.shrink_to_fit();
99+
self.downloaded.shrink_to_fit();
96100
}
97101

98102
pub fn reset_downloading(&mut self, hashes: &[H256]) {
99103
cdebug!(SYNC, "Remove downloading by timeout {:?}", hashes);
100104
for hash in hashes {
101105
self.downloading.remove(&hash);
102106
}
107+
self.downloading.shrink_to_fit();
103108
}
104109

105110
pub fn drain(&mut self) -> Vec<(H256, Vec<UnverifiedTransaction>)> {
@@ -111,7 +116,9 @@ impl BodyDownloader {
111116
break
112117
}
113118
}
119+
self.downloaded.shrink_to_fit();
114120
self.targets.drain(0..result.len());
121+
self.targets.shrink_to_fit();
115122
result
116123
}
117124
}

sync/src/block/downloader/header.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ impl HeaderDownloader {
187187
}
188188
}
189189
}
190+
self.queued.shrink_to_fit();
190191
}
191192

192193
pub fn mark_as_queued(&mut self, hashes: Vec<H256>) {
@@ -195,5 +196,6 @@ impl HeaderDownloader {
195196
self.queued.insert(hash, header);
196197
}
197198
}
199+
self.downloaded.shrink_to_fit();
198200
}
199201
}

0 commit comments

Comments
 (0)