Skip to content

Commit

Permalink
Merge pull request verilog-to-routing#2814 from AlexandreSinger/featu…
Browse files Browse the repository at this point in the history
…re-increase-read-buffer

[Sys] Increased Read Buffers to Reduce Total Syscalls
  • Loading branch information
vaughnbetz authored Nov 18, 2024
2 parents 2ce2c6f + 79caa34 commit c8d3111
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
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

0 comments on commit c8d3111

Please sign in to comment.