Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
一共 3 个改进:
完全使用 utf-8 内码。利用 boost.nowide 实现。在 unix 平台,nowide 是个 no op 操作。避免了 utf16 和 utf8 之间来回转换。在 win 平台, boost.nowide 会对utf8 进行 转 utf16 操作,然后调用 utf16 版的 win api. 相比之前的代码,只有 win 平台有编码转换的问题。主力运行的linux平台,则 避免了转换。而且此修改代码改动极少。很多地方都是直接删除 wide_utf8/utf8_wide 之类的调用。删代码是最好的优化。
对 HTTP server 部分使用了 PMR 分配器。做到内存一次大分配,多次小碎片分配,然后连接完成再一次大释放。相比 非pmr 版本,性能有 50% 的提升。尤其是 列举一个超大的文件夹的时候。
使用asio的异步文件 stream_file 替换之前的 ifstream, 极大的提高了文件传输的效率。同时避免磁盘IO比较高的情况下卡住 web 服务器。对于不支持异步文件IO的平台,还是 fallback 到老的 ifstream。