Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Profile: is coalescing buffers or multiple writes faster? #98

Open
vimpunk opened this issue Jan 8, 2021 · 1 comment
Open

Profile: is coalescing buffers or multiple writes faster? #98

vimpunk opened this issue Jan 8, 2021 · 1 comment

Comments

@vimpunk
Copy link
Owner

vimpunk commented Jan 8, 2021

#95 introduced a fallback for disk writes on other platforms. It currently uses a less efficient approach than the Linux positional vectored IO APIs as they are not present on other platforms.

There were two options for the fallback, quoting directly from the implementation:

                // 1. Coalesce the slices to a continuous preallocated memory buffer and
                //    write it at once.
                // 2. Iterate through the slices and issue a separate write call for each.
                //
                // The first option implies preallocating a short-living buffer
                // and destroying it shortly after. The second option
                // implies issuing a big number of writes, and possibly disk I/O operations.

We should benchmark which is actually faster at some point.

@ExceptionallyHandsome
Copy link
Contributor

ExceptionallyHandsome commented Jan 9, 2021

Any time disk I/O perf is considered, OS caching/buffering must be taken into account.

As things stand with #95 , we use a user-space buffer, and then the OS does its own buffering. I think this double-buffer makes the data transfer slower than it might have been. So yeah, careful and ample benchmarking should become our mantra eventually, but for now it can wait.

In fact, we have not two, but three options to proceed:

  • User-space buffer + OS buffer (current plan on windows & mac, on linux user-space buffer is absent entirely).
  • User-space buffer only. On Windows, OS buffering can be disabled by setting the FILE_FLAG_NO_BUFFERING attribute on creating/opening. Some further info (sounds like aligment-aware allocations will be needed).
  • OS buffer only (the "multiple writes" strategy). This is by the way what libtorrent does.

Also, user-space buffering has its own optimizations to apply...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants