Skip to content

Commit 6d55315

Browse files
committed
[perf] constexpr all (a few of) the things
1 parent 9ce4738 commit 6d55315

24 files changed

Lines changed: 206 additions & 190 deletions

src/archive_manager.cc

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -406,41 +406,42 @@ walk_archive_files(
406406
#endif
407407
}
408408

409-
void
409+
std::future<void>
410410
cleanup_cache()
411411
{
412-
(void) std::async(std::launch::async, []() {
413-
auto now = std::filesystem::file_time_type::clock::now();
414-
auto cache_path = archive_cache_path();
415-
const auto& cfg = injector::get<const config&>();
416-
std::vector<fs::path> to_remove;
417-
418-
log_debug("cache-ttl %d", cfg.amc_cache_ttl.count());
419-
for (const auto& entry : fs::directory_iterator(cache_path)) {
420-
if (entry.path().extension() != ".done") {
421-
continue;
422-
}
412+
return std::async(
413+
std::launch::async, +[]() {
414+
auto now = std::filesystem::file_time_type::clock::now();
415+
auto cache_path = archive_cache_path();
416+
const auto& cfg = injector::get<const config&>();
417+
std::vector<fs::path> to_remove;
423418

424-
auto mtime = fs::last_write_time(entry.path());
425-
auto exp_time = mtime + cfg.amc_cache_ttl;
426-
if (now < exp_time) {
427-
continue;
428-
}
419+
log_debug("cache-ttl %d", cfg.amc_cache_ttl.count());
420+
for (const auto& entry : fs::directory_iterator(cache_path)) {
421+
if (entry.path().extension() != ".done") {
422+
continue;
423+
}
429424

430-
to_remove.emplace_back(entry.path());
431-
}
425+
auto mtime = fs::last_write_time(entry.path());
426+
auto exp_time = mtime + cfg.amc_cache_ttl;
427+
if (now < exp_time) {
428+
continue;
429+
}
432430

433-
for (auto& entry : to_remove) {
434-
log_debug("removing cached archive: %s", entry.c_str());
435-
fs::remove(entry);
431+
to_remove.emplace_back(entry.path());
432+
}
436433

437-
entry.replace_extension(".lck");
438-
fs::remove(entry);
434+
for (auto& entry : to_remove) {
435+
log_debug("removing cached archive: %s", entry.c_str());
436+
fs::remove(entry);
439437

440-
entry.replace_extension();
441-
fs::remove_all(entry);
442-
}
443-
});
438+
entry.replace_extension(".lck");
439+
fs::remove(entry);
440+
441+
entry.replace_extension();
442+
fs::remove_all(entry);
443+
}
444+
});
444445
}
445446

446447
} // namespace archive_manager

src/archive_manager.hh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,13 @@
3333
#define lnav_archive_manager_hh
3434

3535
#include <atomic>
36+
#include <filesystem>
3637
#include <functional>
38+
#include <future>
3739
#include <string>
3840

3941
#include "base/file_range.hh"
4042
#include "base/result.h"
41-
#include <filesystem>
4243
#include "mapbox/variant.hpp"
4344

4445
namespace archive_manager {
@@ -92,7 +93,7 @@ walk_result_t walk_archive_files(
9293
const std::function<void(const std::filesystem::path&,
9394
const std::filesystem::directory_entry&)>&);
9495

95-
void cleanup_cache();
96+
[[nodiscard]] std::future<void> cleanup_cache();
9697

9798
} // namespace archive_manager
9899

src/file_converter_manager.cc

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -152,32 +152,33 @@ convert(const external_file_format& eff, const std::string& filename)
152152
});
153153
}
154154

155-
void
155+
std::future<void>
156156
cleanup()
157157
{
158-
(void) std::async(std::launch::async, []() {
159-
const auto& cfg = injector::get<const lnav::piper::config&>();
160-
auto now = std::filesystem::file_time_type::clock::now();
161-
auto cache_path = cache_dir();
162-
std::vector<std::filesystem::path> to_remove;
163-
164-
for (const auto& entry :
165-
std::filesystem::directory_iterator(cache_path))
166-
{
167-
auto mtime = std::filesystem::last_write_time(entry.path());
168-
auto exp_time = mtime + cfg.c_ttl;
169-
if (now < exp_time) {
170-
continue;
171-
}
158+
return std::async(
159+
std::launch::async, +[]() {
160+
const auto& cfg = injector::get<const lnav::piper::config&>();
161+
auto now = std::filesystem::file_time_type::clock::now();
162+
auto cache_path = cache_dir();
163+
std::vector<std::filesystem::path> to_remove;
164+
165+
for (const auto& entry :
166+
std::filesystem::directory_iterator(cache_path))
167+
{
168+
auto mtime = std::filesystem::last_write_time(entry.path());
169+
auto exp_time = mtime + cfg.c_ttl;
170+
if (now < exp_time) {
171+
continue;
172+
}
172173

173-
to_remove.emplace_back(entry);
174-
}
174+
to_remove.emplace_back(entry);
175+
}
175176

176-
for (auto& entry : to_remove) {
177-
log_debug("removing conversion: %s", entry.c_str());
178-
std::filesystem::remove_all(entry);
179-
}
180-
});
177+
for (auto& entry : to_remove) {
178+
log_debug("removing conversion: %s", entry.c_str());
179+
std::filesystem::remove_all(entry);
180+
}
181+
});
181182
}
182183

183184
} // namespace file_converter_manager

src/file_converter_manager.hh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,14 @@
3030
#ifndef lnav_file_converter_manager_hh
3131
#define lnav_file_converter_manager_hh
3232

33+
#include <filesystem>
34+
#include <future>
3335
#include <string>
3436
#include <vector>
3537

3638
#include "base/auto_pid.hh"
3739
#include "base/result.h"
3840
#include "file_format.hh"
39-
#include <filesystem>
4041

4142
namespace file_converter_manager {
4243

@@ -49,7 +50,8 @@ struct convert_result {
4950
Result<convert_result, std::string> convert(const external_file_format& eff,
5051
const std::string& filename);
5152

52-
void cleanup();
53+
[[nodiscard]]
54+
std::future<void> cleanup();
5355

5456
} // namespace file_converter_manager
5557

src/line_buffer.cc

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1561,36 +1561,37 @@ line_buffer::enable_cache()
15611561
this->lb_cached_fd = std::move(write_fd);
15621562
}
15631563

1564-
void
1564+
std::future<void>
15651565
line_buffer::cleanup_cache()
15661566
{
1567-
(void) std::async(std::launch::async, []() {
1568-
auto now = std::filesystem::file_time_type::clock::now();
1569-
auto cache_path = line_buffer_cache_path();
1570-
std::vector<std::filesystem::path> to_remove;
1571-
std::error_code ec;
1572-
1573-
for (const auto& cache_subdir :
1574-
std::filesystem::directory_iterator(cache_path, ec))
1575-
{
1576-
for (const auto& entry :
1577-
std::filesystem::directory_iterator(cache_subdir, ec))
1567+
return std::async(
1568+
std::launch::async, +[]() {
1569+
auto now = std::filesystem::file_time_type::clock::now();
1570+
auto cache_path = line_buffer_cache_path();
1571+
std::vector<std::filesystem::path> to_remove;
1572+
std::error_code ec;
1573+
1574+
for (const auto& cache_subdir :
1575+
std::filesystem::directory_iterator(cache_path, ec))
15781576
{
1579-
auto mtime = std::filesystem::last_write_time(entry.path());
1580-
auto exp_time = mtime + 1h;
1581-
if (now < exp_time) {
1582-
continue;
1583-
}
1577+
for (const auto& entry :
1578+
std::filesystem::directory_iterator(cache_subdir, ec))
1579+
{
1580+
auto mtime = std::filesystem::last_write_time(entry.path());
1581+
auto exp_time = mtime + 1h;
1582+
if (now < exp_time) {
1583+
continue;
1584+
}
15841585

1585-
to_remove.emplace_back(entry.path());
1586+
to_remove.emplace_back(entry.path());
1587+
}
15861588
}
1587-
}
15881589

1589-
for (auto& entry : to_remove) {
1590-
log_debug("removing compressed file cache: %s", entry.c_str());
1591-
std::filesystem::remove_all(entry, ec);
1592-
}
1593-
});
1590+
for (auto& entry : to_remove) {
1591+
log_debug("removing compressed file cache: %s", entry.c_str());
1592+
std::filesystem::remove_all(entry, ec);
1593+
}
1594+
});
15941595
}
15951596

15961597
void

src/line_buffer.hh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ public:
284284

285285
void send_initial_load();
286286

287-
static void cleanup_cache();
287+
[[nodiscard]] static std::future<void> cleanup_cache();
288288

289289
private:
290290
/**

src/lnav.cc

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,8 @@ using namespace md4cpp::literals;
164164
static std::vector<std::string> DEFAULT_FILES;
165165
static auto intern_lifetime = intern_string::get_table_lifetime();
166166

167+
static std::vector<std::future<void>> CLEANUP_TASKS;
168+
167169
constexpr std::chrono::microseconds ZOOM_LEVELS[] = {
168170
1s,
169171
30s,
@@ -2339,11 +2341,13 @@ VALUES ('org.lnav.mouse-support', -1, DATETIME('now', '+1 minute'),
23392341
}
23402342

23412343
if (!ran_cleanup) {
2342-
line_buffer::cleanup_cache();
2343-
archive_manager::cleanup_cache();
2344-
tailer::cleanup_cache();
2345-
lnav::piper::cleanup();
2346-
file_converter_manager::cleanup();
2344+
CLEANUP_TASKS.emplace_back(line_buffer::cleanup_cache());
2345+
CLEANUP_TASKS.emplace_back(
2346+
archive_manager::cleanup_cache());
2347+
CLEANUP_TASKS.emplace_back(tailer::cleanup_cache());
2348+
CLEANUP_TASKS.emplace_back(lnav::piper::cleanup());
2349+
CLEANUP_TASKS.emplace_back(
2350+
file_converter_manager::cleanup());
23472351
ran_cleanup = true;
23482352
}
23492353
}
@@ -3997,11 +4001,11 @@ SELECT tbl_name FROM sqlite_master WHERE sql LIKE 'CREATE VIRTUAL TABLE%'
39974001

39984002
log_info("Executing initial commands");
39994003
execute_init_commands(lnav_data.ld_exec_context, cmd_results);
4000-
archive_manager::cleanup_cache();
4001-
tailer::cleanup_cache();
4002-
line_buffer::cleanup_cache();
4003-
lnav::piper::cleanup();
4004-
file_converter_manager::cleanup();
4004+
CLEANUP_TASKS.emplace_back(line_buffer::cleanup_cache());
4005+
CLEANUP_TASKS.emplace_back(archive_manager::cleanup_cache());
4006+
CLEANUP_TASKS.emplace_back(tailer::cleanup_cache());
4007+
CLEANUP_TASKS.emplace_back(lnav::piper::cleanup());
4008+
CLEANUP_TASKS.emplace_back(file_converter_manager::cleanup());
40054009
wait_for_pipers();
40064010
rescan_files(true);
40074011
isc::to<curl_looper&, services::curl_streamer_t>()

src/lnav_config.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -583,14 +583,14 @@ static const struct json_path_container keymap_defs_handlers = {
583583
.with_children(keymap_def_handlers),
584584
};
585585

586-
static const json_path_handler_base::enum_value_t _movement_values[] = {
586+
static constexpr json_path_handler_base::enum_value_t _movement_values[] = {
587587
{"top"_frag, config_movement_mode::TOP},
588588
{"cursor"_frag, config_movement_mode::CURSOR},
589589

590590
json_path_handler_base::ENUM_TERMINATOR,
591591
};
592592

593-
static const struct json_path_container movement_handlers = {
593+
static const json_path_container movement_handlers = {
594594
yajlpp::property_handler("mode")
595595
.with_synopsis("top|cursor")
596596
.with_enum_values(_movement_values)
@@ -600,7 +600,7 @@ static const struct json_path_container movement_handlers = {
600600
.for_field<>(&_lnav_config::lc_ui_movement, &movement_config::mode),
601601
};
602602

603-
static const json_path_handler_base::enum_value_t _mouse_mode_values[] = {
603+
static constexpr json_path_handler_base::enum_value_t _mouse_mode_values[] = {
604604
{"disabled"_frag, lnav_mouse_mode::disabled},
605605
{"enabled"_frag, lnav_mouse_mode::enabled},
606606

@@ -1223,7 +1223,7 @@ static const struct json_path_container theme_defs_handlers = {
12231223
.with_children(theme_def_handlers),
12241224
};
12251225

1226-
static const json_path_handler_base::enum_value_t _time_column_values[] = {
1226+
static constexpr json_path_handler_base::enum_value_t _time_column_values[] = {
12271227
{"disabled"_frag, logfile_sub_source_ns::time_column_feature_t::Disabled},
12281228
{"enabled"_frag, logfile_sub_source_ns::time_column_feature_t::Enabled},
12291229
{"default"_frag, logfile_sub_source_ns::time_column_feature_t::Default},

src/lnav_util.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ static const json_path_container snippet_handlers = {
310310
.with_children(attr_line_handlers),
311311
};
312312

313-
static const json_path_handler_base::enum_value_t LEVEL_ENUM[] = {
313+
static constexpr json_path_handler_base::enum_value_t LEVEL_ENUM[] = {
314314
{"raw"_frag, lnav::console::user_message::level::raw},
315315
{"ok"_frag, lnav::console::user_message::level::ok},
316316
{"info"_frag, lnav::console::user_message::level::info},

src/log_format.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3064,7 +3064,7 @@ external_log_format::test_line(sample_t& sample,
30643064
auto md = pat.p_pcre.pp_value->create_match_data();
30653065
auto match_res = pat.p_pcre.pp_value->capture_from(lines[0])
30663066
.into(md)
3067-
.matches()
3067+
.matches(PCRE2_NO_UTF_CHECK)
30683068
.ignore_error();
30693069
if (!match_res) {
30703070
continue;
@@ -4230,7 +4230,8 @@ external_log_format::match_samples(const std::vector<sample_t>& samples) const
42304230
continue;
42314231
}
42324232

4233-
if (pat.p_pcre.pp_value->find_in(sample_iter.s_line.pp_value)
4233+
if (pat.p_pcre.pp_value
4234+
->find_in(sample_iter.s_line.pp_value, PCRE2_NO_UTF_CHECK)
42344235
.ignore_error())
42354236
{
42364237
return true;

0 commit comments

Comments
 (0)