-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Performance significantly worse than libp2p mplex #42
Comments
Some obvious things I see right away
Line 4 in 4007dc4
Turns out that below is not faster // In the top of the file
const allocUnsafeFn = (): (len: number) => Uint8Array => {
if (globalThis.Buffer) {
return globalThis.Buffer.allocUnsafe
}
return (len) => new Uint8Array(len);
}
const allocUnsafe = allocUnsafeFn();
// Later
const frame = allocUnsafe(HEADER_LENGTH) 2). In the decoder, are we using the data length available in the header to allocate the right size for the Uint8ArrayList? It seems to currently only be used as a break condition. |
Still left
|
@marcus-pousette thanks for creating this issue, afaik yamux should have no performance penalties. @MarcoPolo can you confirm? additionally, once libp2p/test-plans has benchmarking setup for js-libp2p, we should be able to observe this discrepancy between mplex and yamux right? |
I see, then it is in the implementation details I guess. There is a benchmark setup in this lib, and the output also shows that there is a discrepancy I am running the benchmark from master and get this
There is almost a factor 2x difference between yamux and mplex for some of the runs here |
I tried to run the VSCode profiler for the benchmark tasks but the results given are very opaque, sadly (fail to get any real insights) |
Yamux has historically been slower than mplex but it’s not had the same amount of profiling applied so there is almost certainly some low hanging fruit to be had. @marcus-pousette thank you for looking into this |
Yeap! It should be a low hanging fruit for this one. I have not found anything critical yet, but...
|
Posting benchmark from running it today codec benchmark comparison benchmark Still see a big difference in performance for many of the cases. Perhaps especially for |
The mplex implementation using a "buffer pool" for the encoder, while this implementation is not. I wonder whether that could play a part here: That there is a lot of allocation/deallocation of memory that only lives for a short amount of time |
We've done some real-world benchmarking which has led to some performance improvements and the results are that js-libp2p has the fastest streaming performance of the libp2p implementations tested - https://observablehq.com/@libp2p-workspace/performance-dashboard I'm going to close this as yamux has closed the performance gap and has back pressure so is vastly preferable to mplex. Please re-open if you're still seeing a serious degradation. |
I am considering replacing all my dependencies on
@libp2p/mplex
with this yamux implementation in my project.However, I am experiencing significant performance loss with this change. In my benchmark, where I do replication work between multiple nodes I am able to do around 1200 tps with @libp2p/mplex but only around 700 with yamux.
I have not deep dived into the details of mplex and yamux, but is it technically possible to reach same performance in a yamux implementation as with mplex? Or am I seeing loss of performance as a cost of the features yamux brings to the table?
The text was updated successfully, but these errors were encountered: