Skip to content

Commit d6ece2c

Browse files
committed
[perf] disable extra compression in line_buffer for non-logfile uses
1 parent b2e4b1c commit d6ece2c

5 files changed

Lines changed: 25 additions & 8 deletions

File tree

src/file_format.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@
4444
detect_file_format_result
4545
detect_file_format(const std::filesystem::path& filename)
4646
{
47+
// static auto op = lnav_operation{"detect_file_format"};
48+
// auto op_guard = lnav_opid_guard::internal(op);
4749
log_trace("detecting format of file: %s", filename.c_str());
4850

4951
detect_file_format_result retval = {file_format_t::UNKNOWN};

src/files_sub_source.cc

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -521,10 +521,6 @@ files_sub_source::text_update_marks(vis_bookmarks& bm)
521521
}
522522
index += 1_vl;
523523
}
524-
525-
log_debug("files bookmarks errors=%zu; warnings=%zu",
526-
bm_errs.size(),
527-
bm_warn.size());
528524
}
529525

530526
void

src/line_buffer.cc

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,9 @@ line_buffer::set_fd(auto_fd& fd)
471471
if (!hdr.empty()) {
472472
this->lb_header = std::move(hdr);
473473
}
474-
this->resize_buffer(INITIAL_COMPRESSED_BUFFER_SIZE);
474+
if (this->lb_decompress_extra) {
475+
this->resize_buffer(INITIAL_COMPRESSED_BUFFER_SIZE);
476+
}
475477
}
476478
#ifdef HAVE_BZLIB_H
477479
else if (gz_id[0] == 'B' && gz_id[1] == 'Z')
@@ -486,7 +488,9 @@ line_buffer::set_fd(auto_fd& fd)
486488
* Loading data from a bzip2 file is pretty slow, so we try
487489
* to keep as much in memory as possible.
488490
*/
489-
this->resize_buffer(INITIAL_COMPRESSED_BUFFER_SIZE);
491+
if (this->lb_decompress_extra) {
492+
this->resize_buffer(INITIAL_COMPRESSED_BUFFER_SIZE);
493+
}
490494

491495
this->lb_compressed_offset = 0;
492496
}
@@ -1038,7 +1042,9 @@ line_buffer::fill_range(file_off_t start,
10381042
* For compressed files, increase the buffer size so we
10391043
* don't have to spend as much time uncompressing the data.
10401044
*/
1041-
this->resize_buffer(MAX_COMPRESSED_BUFFER_SIZE);
1045+
if (this->lb_decompress_extra) {
1046+
this->resize_buffer(MAX_COMPRESSED_BUFFER_SIZE);
1047+
}
10421048
}
10431049
break;
10441050

@@ -1298,6 +1304,9 @@ line_buffer::load_next_line(file_range prev_line)
12981304

12991305
offset += retval.li_file_range.fr_size;
13001306

1307+
done = true;
1308+
} else if (!retval.li_utf8_scan_result.is_valid()) {
1309+
retval.li_partial = true;
13011310
done = true;
13021311
} else {
13031312
if (!this->is_pipe() || !this->is_pipe_closed()) {

src/line_buffer.hh

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public:
9999
gz_indexed(gz_indexed&& other) = default;
100100
~gz_indexed() { this->close(); }
101101

102-
inline operator bool() const { return this->gz_fd != -1; }
102+
operator bool() const { return this->gz_fd != -1; }
103103

104104
uLong get_source_offset() const
105105
{
@@ -149,6 +149,11 @@ public:
149149

150150
bool get_do_preloading() const { return this->lb_do_preloading; }
151151

152+
bool set_decompress_extra(bool value)
153+
{
154+
return this->lb_decompress_extra = value;
155+
}
156+
152157
/** @param fd The file descriptor that data should be pulled from. */
153158
void set_fd(auto_fd& fd);
154159

@@ -388,6 +393,7 @@ private:
388393
time_t lb_file_time{0};
389394
bool lb_seekable{false}; /*< Flag set for seekable file descriptors. */
390395
bool lb_compressed{false};
396+
bool lb_decompress_extra{false};
391397
bool lb_is_utf8{true};
392398
bool lb_do_preloading{false};
393399
file_off_t lb_last_line_offset{-1}; /*< */

src/logfile.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ logfile::logfile(std::filesystem::path filename,
247247
: lf_filename(std::move(filename)),
248248
lf_filename_as_string(lf_filename.string()), lf_options(loo)
249249
{
250+
this->lf_line_buffer.set_decompress_extra(true);
250251
this->lf_opids.writeAccess()->los_opid_ranges.reserve(64);
251252
this->lf_thread_ids.writeAccess()->ltis_tid_ranges.reserve(64);
252253
}
@@ -1093,6 +1094,9 @@ logfile::rebuild_index(std::optional<ui_clock::time_point> deadline)
10931094
static const auto& dts_cfg
10941095
= injector::get<const date_time_scanner_ns::config&>();
10951096

1097+
static auto op = lnav_operation{"rebuild_file_index"};
1098+
auto op_guard = lnav_opid_guard::internal(op);
1099+
10961100
if (!this->lf_invalidated_opids.empty()) {
10971101
auto writeOpids = this->lf_opids.writeAccess();
10981102

0 commit comments

Comments
 (0)