perf: remove cpu bottleneck in tr_peerIo::write() (#4258)

This commit is contained in:
Charles Kerr 2022-11-27 20:46:03 -06:00 committed by GitHub
parent d8327949ac
commit 0efb96124b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 5 deletions

View File

@ -796,11 +796,8 @@ size_t tr_peerIo::getWriteBufferSpace(uint64_t now) const noexcept
void tr_peerIo::write(libtransmission::Buffer& buf, bool is_piece_data)
{
for (auto& ch : buf)
{
encrypt(1, &ch);
}
auto [bytes, len] = buf.pullup();
encrypt(len, bytes);
outbuf_info.emplace_back(std::size(buf), is_piece_data);
outbuf.add(buf);
}

View File

@ -266,6 +266,11 @@ public:
return iov;
}
[[nodiscard]] std::pair<std::byte*, size_t> pullup()
{
return { reinterpret_cast<std::byte*>(evbuffer_pullup(buf_.get(), -1)), size() };
}
void commit(Iovec iov)
{
evbuffer_commit_space(buf_.get(), &iov, 1);