Refactor FFI analytics to track only successful completions

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 <noreply@anthropic.com>
This commit is contained in:
Claude Bot
2025-10-27 23:49:03 +00:00
parent 6a6e861ded
commit a8eb01cf2e

View File

@@ -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();