From a8eb01cf2e3ba014e993f904b757f2d11d220de9 Mon Sep 17 00:00:00 2001 From: Claude Bot Date: Mon, 27 Oct 2025 23:49:03 +0000 Subject: [PATCH] Refactor FFI analytics to track only successful completions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Move analytics.Features.ffi increments from internal compile functions to the JS host function return points. This ensures we only count FFI usage when operations successfully complete and return to JavaScript: - dlopen (FFI.open): Increment after library loads and symbols compile - TCC compile (Bun__FFI__cc): Increment after C code compiles successfully - Callbacks (FFI.callback): Increment after callback wrapper compiles Removed increments from internal helpers (CompileC.compile, Function.compile, Function.compileCallback) to avoid double-counting. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- src/bun.js/api/ffi.zig | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/bun.js/api/ffi.zig b/src/bun.js/api/ffi.zig index 1f300a6113..cd246bd55a 100644 --- a/src/bun.js/api/ffi.zig +++ b/src/bun.js/api/ffi.zig @@ -319,8 +319,6 @@ pub const FFI = struct { } pub fn compile(this: *CompileC, globalThis: *JSGlobalObject) !struct { *TCC.State, []u8 } { - bun.analytics.Features.ffi += 1; - const compile_options: [:0]const u8 = if (this.flags.len > 0) this.flags else if (bun.env_var.BUN_TCC_OPTIONS.get()) |tcc_options| @@ -804,6 +802,8 @@ pub const FFI = struct { bytes_to_free_on_error = ""; compile_c.symbols = .{}; + bun.analytics.Features.ffi += 1; + const js_object = lib.toJS(globalThis); jsc.Codegen.JSFFI.symbolsValueSetCached(js_object, globalThis, obj); return js_object; @@ -853,6 +853,7 @@ pub const FFI = struct { .compiled => { const function_ = bun.default_allocator.create(Function) catch unreachable; function_.* = func.*; + bun.analytics.Features.ffi += 1; return JSValue.createObject2( globalThis, ZigString.static("ptr"), @@ -1068,8 +1069,6 @@ pub const FFI = struct { }; }; - bun.analytics.Features.ffi += 1; - var size = symbols.values().len; if (size >= 63) { size = 0; @@ -1153,6 +1152,8 @@ pub const FFI = struct { .functions = symbols, }); + bun.analytics.Features.ffi += 1; + const js_object = lib.toJS(global); jsc.Codegen.JSFFI.symbolsValueSetCached(js_object, global, obj); return js_object; @@ -1516,8 +1517,6 @@ pub const FFI = struct { const tcc_options = "-std=c11 -nostdlib -Wl,--export-all-symbols" ++ if (Environment.isDebug) " -g" else ""; pub fn compile(this: *Function, napiEnv: ?*napi.NapiEnv) !void { - bun.analytics.Features.ffi += 1; - var source_code = std.ArrayList(u8).init(this.allocator); var source_code_writer = source_code.writer(); try this.printSourceCode(&source_code_writer); @@ -1592,8 +1591,6 @@ pub const FFI = struct { js_function: JSValue, is_threadsafe: bool, ) !void { - bun.analytics.Features.ffi += 1; - jsc.markBinding(@src()); var source_code = std.ArrayList(u8).init(this.allocator); var source_code_writer = source_code.writer();