Skip to content

Commit f058c4e

Browse files
authored
fix: FT.CREATE first-query initialization penalty (slowdown) (#5473)
Fixed: #5472
1 parent 0b01cc5 commit f058c4e

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/server/search/search_family.cc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <vector>
1616

1717
#include "base/logging.h"
18+
#include "core/search/query_driver.h"
1819
#include "core/search/search.h"
1920
#include "core/search/vector_utils.h"
2021
#include "facade/cmd_arg_parser.h"
@@ -619,9 +620,23 @@ void SearchReply(const SearchParams& params,
619620
}
620621
}
621622

623+
// Warms up the query parser to avoid first-call slowness
624+
void WarmupQueryParser() {
625+
static std::once_flag warmed_up;
626+
std::call_once(warmed_up, []() {
627+
search::QueryParams params;
628+
search::QueryDriver driver{};
629+
driver.SetParams(&params);
630+
driver.SetInput(std::string{""});
631+
(void)search::Parser (&driver)();
632+
});
633+
}
634+
622635
} // namespace
623636

624637
void SearchFamily::FtCreate(CmdArgList args, const CommandContext& cmd_cntx) {
638+
WarmupQueryParser();
639+
625640
auto* builder = cmd_cntx.rb;
626641
if (cmd_cntx.conn_cntx->conn_state.db_index != 0) {
627642
return builder->SendError("Cannot create index on db != 0"sv);

0 commit comments

Comments
 (0)