src: cache trace category lookups on hot paths

The sync fs, fs dir, AsyncWrap and vm.Script tracing guards called
TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED directly, which does a
by-name search in the tracing controller on every call. Use
TRACE_EVENT_CATEGORY_ENABLED instead, which caches the category
pointer per call site like the other TRACE_EVENT macros. Perfetto
already provides it; add an equivalent for the legacy tracing build.

Assisted-by: claude:opus-5.5
Signed-off-by: Gürgün Dayıoğlu <hey@gurgun.day>
PR-URL: https://github.com/nodejs/node/pull/67502
Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
Gürgün Dayıoğlu authored and Antoine du Hamel committed 2026-11-25 18:00:57 +01:00
1 parent e56889e0b9
commit b087c23396
5 files changed
+12 -8

No files matched your search

+1 -2
View File
@@ -111,8 +111,7 @@ void AsyncWrap::EmitPromiseResolve(Environment* env, double async_id) {
}
void AsyncWrap::EmitTraceAsyncStart() const {
if (*TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED(
TRACING_CATEGORY_NODE1(async_hooks))) {
if (TRACE_EVENT_CATEGORY_ENABLED(TRACING_CATEGORY_NODE1(async_hooks))) {
tracing::AsyncWrapArgs data(env()->execution_async_id(),
get_trigger_async_id());
TRACE_EVENT_NESTABLE_ASYNC_BEGIN1(TRACING_CATEGORY_NODE1(async_hooks),
+1 -2
View File
@@ -1014,8 +1014,7 @@ void ContextifyScript::New(const FunctionCallbackInfo<Value>& args) {
ContextifyScript* contextify_script = New(env, args.This());
if (*TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED(
TRACING_CATEGORY_NODE2(vm, script)) != 0) {
if (TRACE_EVENT_CATEGORY_ENABLED(TRACING_CATEGORY_NODE2(vm, script))) {
Utf8Value fn(isolate, filename);
TRACE_EVENT_BEGIN1(TRACING_CATEGORY_NODE2(vm, script),
"ContextifyScript::New",
+1 -2
View File
@@ -61,8 +61,7 @@ static const char* get_dir_func_name_by_type(uv_fs_type req_type) {
#define TRACE_NAME(name) "fs_dir.sync." #name
#define GET_TRACE_ENABLED \
(*TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED( \
TRACING_CATEGORY_NODE2(fs_dir, sync)) != 0)
TRACE_EVENT_CATEGORY_ENABLED(TRACING_CATEGORY_NODE2(fs_dir, sync))
#define FS_DIR_SYNC_TRACE(syscall) \
if (GET_TRACE_ENABLED) { \
TRACE_EVENT0(TRACING_CATEGORY_NODE2(fs_dir, sync), TRACE_NAME(syscall)); \
+1 -2
View File
@@ -165,8 +165,7 @@ static const char* get_fs_func_name_by_type(uv_fs_type req_type) {
#define TRACE_NAME(name) "fs.sync." #name
#define GET_TRACE_ENABLED \
(*TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED( \
TRACING_CATEGORY_NODE2(fs, sync)) != 0)
TRACE_EVENT_CATEGORY_ENABLED(TRACING_CATEGORY_NODE2(fs, sync))
// Checks a permission for an fs binding. A denial is reported through
// `req_wrap_async` for an asynchronous call, or thrown for a synchronous call
// (when `req_wrap_async` is nullptr).
+8
View File
@@ -1012,6 +1012,14 @@
} \
} while (0)
// Expression form of the above, matching Perfetto's macro of the same name.
#define TRACE_EVENT_CATEGORY_ENABLED(category_group) \
([] { \
bool enabled; \
TRACE_EVENT_CATEGORY_GROUP_ENABLED(category_group, &enabled); \
return enabled; \
}())
// Macro to explicitly warm up a given category group. This could be useful in
// cases where we want to initialize a category group before any trace events
// for that category group is reported. For example, to have a category group