From 4c6d7d2d2032d0a8ba62282dc94cbdad746b4099 Mon Sep 17 00:00:00 2001 From: araq Date: Sun, 30 Aug 2026 23:55:58 +0200 Subject: [PATCH] IC: time the export branch's two halves, so the next lever is sized MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `processTopLevel`'s `export` branch is 484ms of an 8.64s build, and the split matters for what to do about it: `resolveSym` is 118ms, `addReexportedEnumFields` is 290ms over 34815 exported symbols — 8.3us each. That cost is one line: `addReexportedEnumFields` calls `loadSym` to force the symbol out of `Partial` state and THEN asks whether it is a non-pure enum type. Almost none of them are, so nearly all of that is a full symbol decode done to answer a question the def's header already contains — a sym is written as `(sd ...)`, so the kind is two tokens in. Not fixed here, deliberately. A peek would have to hand-walk that layout, and mis-stepping it misclassifies silently rather than failing; it is worth doing with an oracle beside it, the way `indexFromBif` was. Sized and recorded so the next person starts from a number instead of a hunch. Timers only — no behaviour change; verified 67/67 `.c` byte-identical. Co-Authored-By: Claude Opus 5 Claude-Session: https://claude.ai/code/session_01FMyRHByv7hhaQJ4Pa1bHbE --- compiler/ast2nif.nim | 4 ++++ compiler/icprof.nim | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/compiler/ast2nif.nim b/compiler/ast2nif.nim index 4a65f7d5da..c517aef48a 100644 --- a/compiler/ast2nif.nim +++ b/compiler/ast2nif.nim @@ -4140,10 +4140,14 @@ proc processTopLevel(c: var DecodeContext; cur: var Cursor; flags: set[LoadFlag] # being compiled fresh (they would collide with the fresh originals). if c.mainModuleSuffix.len == 0 or parseSymName(symAsStr).module != c.mainModuleSuffix: + icProfStart(tResolveSym) let sym = resolveSym(c, symAsStr, false) + icProfStop(tResolveSym) if sym != nil: strTableAdd(interf, sym) + icProfStart(tEnumFields) addReexportedEnumFields(c, sym, interf) + icProfStop(tEnumFields) skip cur else: raiseAssert "expected Symbol or ParRi but got " & $cur.kind & diff --git a/compiler/icprof.nim b/compiler/icprof.nim index 32fefcc0b3..8f95594394 100644 --- a/compiler/icprof.nim +++ b/compiler/icprof.nim @@ -36,7 +36,7 @@ when defined(icBNodeProf): TimeSlot* = enum tLoadClosure, tModuleId, tBifLoad, tPosIndex, tTopLevel, tInterfTables, tTransform, tHandOff, tGenBody, tAnalyses, - tSym, tTyp, tInfo, tOrigin, tExportBranch + tSym, tTyp, tInfo, tOrigin, tExportBranch, tResolveSym, tEnumFields var profCounts: array[ProfSlot, int] var profNanos: array[TimeSlot, int64]