This repository has been archived by the owner on Feb 12, 2024. It is now read-only.
Pinning takes longer the more pins exist #3759
Labels
exp/intermediate
Prior experience is likely helpful
kind/enhancement
A net-new feature or improvement to an existing feature
kind/resolved-in-helia
need/analysis
Needs further analysis before proceeding
P2
Medium: Good to have, but can wait until someone steps up
topic/perf
Performance
Linux philsklapparch 5.12.12-arch1-1 #1 SMP PREEMPT Fri, 18 Jun 2021 21:59:22 +0000 x86_64 GNU/Linux
Severity: Medium
Description:
As discussed in #2650 (comment), I've created a benchmark suite to show what I've found: js-ipfs performs worse the more pins you have.
I've created rudimentary benchmark suite and here are some graphs from the data I collected (link to google sheet):
This graph shows the time for the
![image](https://user-images.githubusercontent.com/1430958/126533236-e3e79cef-76cd-4da4-a9c5-3475b3484d68.png)
n
thipfs.add(<random data>, { pin: true })
, with a js-ipfs instance that's configured withMemoryDatastore
s:You can clearly see a linear increase in the baseline time it takes for later adds. While the first couple of adds take between 3-5ms, the 3000th add takes between 40-50ms.
This graph shows the time for the
![image](https://user-images.githubusercontent.com/1430958/126535155-a668629f-4855-4158-99e2-b1aaca40eeb5.png)
n
thipfs.add(<random data>, { pin: false })
, with a js-ipfs instance configured in the same way as the one above:You can clearly see that there is no runtime increase after even 3000 adds. All adds except outliers take between 1-2ms.
Steps to reproduce the error:
You can try to reproduce my findings using my reproduction repository.
Also, the graphs above show performance for an in-memory IPFS (with
MemoryDatastore
s), but they're also reproducible for normal IPFS configurations, it's just much noisier.I've done some performance profiling with v8, and one cost center I'm seeing is this function:
js-ipfs/packages/ipfs-core/src/components/pin/add-all.js
Lines 34 to 54 in 91a84e4
The
isPinnedWithType
function takes longer the more pins you have. That's likely what's causing the above issue.I think there are a couple of possible improvements:
await repo.pins.isPinnedWithType(cid, [PinTypes.recursive, PinTypes.direct])
is very costly. We can skip this check ifrecursive
is true. I.e. ifrecursive
is true, the condition on line 41 is false anyway and the result ofisPinnedWithType
is unused anyway. I'm assuming that it doesn't have side-effects.PinType.direct
when onlyrecursive
pins have an effect in line 41?Most likely my assumption that
isPinnedWithType
doesn't have side-effects is just wrong 🤷♂️Anyway, I have much less expertise with the ipfs-core codebase anyway, but I hope I was helpful.
The text was updated successfully, but these errors were encountered: