Skip to content

[Sys] Increased Read Buffers to Reduce Total Syscalls #2814

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

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions libs/EXTERNAL/libblifparse/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ add_library(libblifparse STATIC
target_include_directories(libblifparse PUBLIC ${LIB_INCLUDE_DIRS} ${CMAKE_CURRENT_BINARY_DIR})
set_target_properties(libblifparse PROPERTIES PREFIX "") #Avoid extra 'lib' prefix

# Set the read buffer size in the generated lexers. This reduces the number of
# syscalls since the default is only 1kB.
target_compile_definitions(libblifparse PRIVATE YY_READ_BUF_SIZE=1048576)

#Create the test executable
add_executable(blifparse_test src/main.cpp)
target_link_libraries(blifparse_test libblifparse)
Expand Down
10 changes: 8 additions & 2 deletions libs/libpugiutil/src/pugixml_loc.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
#include <cstdio>
#include <algorithm>
#include <vector>
#include "pugixml_util.hpp"
#include "pugixml_loc.hpp"

// The size of the read buffer when reading from a file.
#ifndef PUGI_UTIL_READ_BUF_SIZE
#define PUGI_UTIL_READ_BUF_SIZE 1048576
#endif // PUGI_UTIL_READ_BUF_SIZE

namespace pugiutil {

//Return the line number from the given offset
Expand Down Expand Up @@ -30,10 +36,10 @@ void loc_data::build_loc_data() {

std::ptrdiff_t offset = 0;

char buffer[1024];
std::vector<char> buffer(PUGI_UTIL_READ_BUF_SIZE);
std::size_t size;

while ((size = fread(buffer, 1, sizeof(buffer), f)) > 0) {
while ((size = fread(buffer.data(), 1, buffer.size() * sizeof(char), f)) > 0) {
for (std::size_t i = 0; i < size; ++i) {
if (buffer[i] == '\n') {
offsets_.push_back(offset + i);
Expand Down
9 changes: 7 additions & 2 deletions libs/libvtrutil/src/vtr_digest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,15 @@

#include <iostream>
#include <fstream>
#include <array>
#include <vector>

#include "picosha2.h"

// The size of the read buffer when reading from a file.
#ifndef VTR_UTIL_READ_BUF_SIZE
#define VTR_UTIL_READ_BUF_SIZE 1048576
#endif // VTR_UTIL_READ_BUF_SIZE

namespace vtr {

std::string secure_digest_file(const std::string& filepath) {
Expand All @@ -21,7 +26,7 @@ std::string secure_digest_stream(std::istream& is) {
//Read the stream in chunks and calculate the SHA256 digest
picosha2::hash256_one_by_one hasher;

std::array<char, 1024> buf;
std::vector<char> buf(VTR_UTIL_READ_BUF_SIZE);
while (!is.eof()) {
//Process a chunk
is.read(buf.data(), buf.size());
Expand Down