irc: add timing measurements; formatting

Signed-off-by: NotAShelf <raf@notashelf.dev>
Change-Id: Id4402547e18b6569464850c3753383396a6a6964
This commit is contained in:
raf 2026-02-23 02:23:44 +03:00
commit 84cf5fdf68
Signed by: NotAShelf
GPG key ID: 29D95B64378DB4BF
2 changed files with 16 additions and 3 deletions

View file

@ -388,7 +388,7 @@ struct Deserializer::Impl {
uint32_t num_elements = read_u32(); uint32_t num_elements = read_u32();
std::vector<std::shared_ptr<Node>> elements; std::vector<std::shared_ptr<Node>> elements;
elements.reserve(num_elements); elements.reserve(num_elements);
for (uint32_t i = 0; i < num_elements; i++) { for (uint32_t i = 0; i < num_elements; i++) {
elements.push_back(read_node()); elements.push_back(read_node());
} }
return std::make_shared<Node>(ListNode(std::move(elements), line)); return std::make_shared<Node>(ListNode(std::move(elements), line));

View file

@ -12,6 +12,7 @@
#include "irc/serializer.h" #include "irc/serializer.h"
#include "irc/types.h" #include "irc/types.h"
#include <chrono>
#include <iostream> #include <iostream>
namespace nix_ir_plugin { namespace nix_ir_plugin {
@ -29,6 +30,8 @@ static void prim_loadIR(EvalState& state, const PosIdx pos, Value** args, Value&
std::string pathStr(path); std::string pathStr(path);
auto t_start = std::chrono::high_resolution_clock::now();
Deserializer deserializer; Deserializer deserializer;
IRModule module; IRModule module;
@ -38,6 +41,8 @@ static void prim_loadIR(EvalState& state, const PosIdx pos, Value** args, Value&
state.error<EvalError>("failed to deserialize IR bundle: %s", e.what()).atPos(pos).debugThrow(); state.error<EvalError>("failed to deserialize IR bundle: %s", e.what()).atPos(pos).debugThrow();
} }
auto t_deser = std::chrono::high_resolution_clock::now();
if (!module.entry) { if (!module.entry) {
state.error<EvalError>("IR bundle has no entry point").atPos(pos).debugThrow(); state.error<EvalError>("IR bundle has no entry point").atPos(pos).debugThrow();
} }
@ -48,6 +53,14 @@ static void prim_loadIR(EvalState& state, const PosIdx pos, Value** args, Value&
} catch (const std::exception& e) { } catch (const std::exception& e) {
state.error<EvalError>("failed to evaluate IR: %s", e.what()).atPos(pos).debugThrow(); state.error<EvalError>("failed to evaluate IR: %s", e.what()).atPos(pos).debugThrow();
} }
auto t_eval = std::chrono::high_resolution_clock::now();
auto deser_us = std::chrono::duration_cast<std::chrono::microseconds>(t_deser - t_start).count();
auto eval_us = std::chrono::duration_cast<std::chrono::microseconds>(t_eval - t_deser).count();
std::cerr << "nixIR timing: deser=" << deser_us << "us eval=" << eval_us
<< "us total=" << (deser_us + eval_us) << "us" << std::endl;
} }
/** /**
@ -139,7 +152,7 @@ static RegisterPrimOp rp_info({
} // namespace nix_ir_plugin } // namespace nix_ir_plugin
// Plugin initialization message // Plugin initialization
__attribute__((constructor)) static void init_plugin() { __attribute__((constructor)) static void init_plugin() {
std::cerr << "nix-ir-plugin loaded" << std::endl; // Plugin loads silently...
} }