-
Notifications
You must be signed in to change notification settings - Fork 177
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Optimize index creation time (#1240)
### What problem does this PR solve? * Use loser tree to replace normal heap * Optimize io and use mmap to replace fread * Reconstruct merge and predic threads using ring queues * Reconstruct merge and output threads using output queues * Adjust the intermediate file output format and reduce the size of the intermediate file * Reconstruct the locks between merge, predic, and output threads to reduce lock granularity ### Type of change - [x] Refactoring - [x] Performance Improvement - [x] Test cases
- Loading branch information
Showing
12 changed files
with
1,010 additions
and
184 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
module; | ||
|
||
#include <cstring> | ||
#include <cstdio> | ||
|
||
export module buf_writer; | ||
import stl; | ||
|
||
namespace infinity { | ||
// A simple buffer writer that writes data to a file. | ||
// Now only used for ColumnInverter | ||
// ColumnInverter will use BufWriter sequentially write data and use spill_file pointer randomly write data | ||
export struct BufWriter { | ||
BufWriter(FILE *spill_file, SizeT spill_buf_size) : spill_file_(spill_file), spill_buf_size_(spill_buf_size) { | ||
spill_buffer_ = MakeUnique<char_t[]>(spill_buf_size_); | ||
} | ||
|
||
void Write(const char* data, SizeT data_size) { | ||
if (spill_buf_idx_ + data_size > spill_buf_size_) { | ||
Flush(); | ||
} | ||
memcpy(spill_buffer_.get() + spill_buf_idx_, data, data_size); | ||
spill_buf_idx_ += data_size; | ||
} | ||
|
||
void Flush() { | ||
if (spill_buf_idx_) { | ||
fwrite(spill_buffer_.get(), spill_buf_idx_, 1, spill_file_); | ||
spill_buf_idx_ = 0; | ||
} | ||
} | ||
|
||
SizeT Tell() { | ||
return ftell(spill_file_); | ||
} | ||
|
||
FILE *spill_file_{nullptr}; | ||
SizeT spill_buf_idx_{0}; | ||
UniquePtr<char_t[]> spill_buffer_{}; | ||
SizeT spill_buf_size_{0}; | ||
}; | ||
} |
Oops, something went wrong.