js-libp2p-gossipsub
js-libp2p-gossipsub copied to clipboard
perf: improve metric performance
Motivation
gauge.inc()takes 2.45% cpu time which is > 2 / 3runHeartbeat()cpu time
Description
gauge.inc()will hash the label objects and push to Map every time we call it- so we we write some cached gauge metric class to only do that when scrape
- gauge has no label: use
NoLabelCachedGauge, this gives 7x improvement - gauge has 1 label: use
OneLabelCachedGauge, this gives 1.2x improvement - gauge has 2 labels: use
TwoLabelCachedGauge, this gives 2.5x improvement
- gauge has no label: use
- also remove unnecessary gauge metric
also remove unnecessary gauge metric
@tuyennhv Could you do this item in a separate PR?
About the optimization, is it best to do it here or on Lodestar?
Codecov Report
Merging #287 (43db65b) into master (475c861) will decrease coverage by
1.50%. The diff coverage is21.06%.
:exclamation: Current head 43db65b differs from pull request most recent head dc3c677. Consider uploading reports for the commit dc3c677 to get more accurate results
@@ Coverage Diff @@
## master #287 +/- ##
==========================================
- Coverage 80.46% 78.96% -1.51%
==========================================
Files 42 42
Lines 9102 9384 +282
Branches 826 825 -1
==========================================
+ Hits 7324 7410 +86
- Misses 1778 1974 +196
| Impacted Files | Coverage Δ | |
|---|---|---|
| src/metrics.ts | 25.20% <21.02%> (+2.11%) |
:arrow_up: |
| src/index.ts | 69.42% <25.00%> (ø) |
Continue to review full report at Codecov.
Legend - Click here to learn more
Δ = absolute <relative> (impact),ø = not affected,? = missing dataPowered by Codecov. Last update 475c861...dc3c677. Read the comment docs.
closing as this PR was merged https://github.com/ChainSafe/js-libp2p-gossipsub/pull/433