Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

perf(frontend): shrink the logged-out boot graph and reset its budget (#99026)

Paul D'Ambra23ac79f13a51
diff --git a/frontend/bin/check-eager-graph.mjs b/frontend/bin/check-eager-graph.mjs
index ef3798dc6f7c..be01f9c89ec7 100644
--- a/frontend/bin/check-eager-graph.mjs
+++ b/frontend/bin/check-eager-graph.mjs
@@ -23,24 +23,24 @@ const failForbiddenHits = process.argv.includes('--fail-forbidden-hits')
// The eager graph is everything a root actually SHIPS on the critical path — the bytes a
// browser downloads and parses before that surface is interactive. It is measured from the
// esbuild OUTPUT chunks: the root's entry chunk plus every chunk reachable through static
-// (import-statement) chunk edges, plus each visited chunk's attached stylesheet (cssBundle,
-// which is downloaded before render). Lazy (dynamic-import) chunks are excluded, and tree-shaken
+// (import-statement) chunk edges, plus the one stylesheet the page links (see `linkedStylesheet`;
+// it is downloaded before render). Lazy (dynamic-import) chunks are excluded, and tree-shaken
// code is already gone from the output — so a side-effect-free re-export barrel only costs
// what its used exports actually ship, not its whole surface (the earlier input-graph metric
// counted the whole barrel and mistook reachability for shipped weight).
// Total dist size can't see this regression class (a fake-lazy import moves no total bytes
// but shifts them onto the eager path), which is why this check exists.
//
-// Budgets are eager output bytes (shipped JS + eager CSS, minified).
+// Budgets are eager output bytes (shipped JS + the linked stylesheet, minified).
// Ratchet policy: when a bundle-splitting win lands, lower the budget to lock it in;
// raise a budget only as a conscious, reviewed decision in the PR that needs it.
const ROOTS = [
{
root: 'src/index.tsx',
label: 'entry (logged-out pages, app bootstrap)',
- // 2026-07-01: 3.75 MiB eager output (2.73 MiB JS + 1.02 MiB eager CSS, 21 chunks).
+ // 2026-09-11: 1.54 MiB eager output (0.18 MiB JS + the 1.36 MiB linked stylesheet, 22 files).
// ~20% headroom so routine churn doesn't trip the warn; ratchet down on a split win.
- budgetBytes: 4_725_000,
+ budgetBytes: 1_930_000,
forbidden: [
'node_modules/monaco-editor/',
'src/lib/components/ActivityLog/describers',
@@ -67,26 +67,31 @@ const ROOTS = [
root: ['src/index.tsx', 'src/scenes/App.tsx', 'src/scenes/bootApp.ts'],
label: 'logged-out boot: index + App + bootApp (preloaded by every page, including /login)',
// The backend preloads the App closure for logged-out pages too (preload-manifest.json
- // `js`), so this is the whole JS cost of /login. 2026-09-03: 5.14 MiB eager output = 2.55 MiB
- // JS (37 chunks) + the three entries' stylesheets (2.60 MiB, of which only index's is linked
- // at runtime; the others are esbuild's per-entry copies). Before this stack the JS alone was
- // 7.5 MiB. ~15% headroom so routine churn doesn't trip the warn; ratchet down on a split win.
- budgetBytes: 5_900_000,
+ // `js`), so this is the whole JS cost of /login. 2026-09-11: 3.51 MiB eager output = 2.14 MiB
+ // JS (608 files) + the 1.36 MiB linked stylesheet.
+ // ~15% headroom so routine churn doesn't trip the warn; ratchet down on a split win.
+ budgetBytes: 4_225_000,
forbidden: [
'node_modules/monaco-editor/',
// Authenticated-only code. Either of these on the App path means a component that
// logged-out pages render has grown a static import into the logged-in app.
'src/layout/navigation-3000/navigationLogic.tsx',
'src/scenes/dashboard/dashboardLogic.tsx',
+ // Nothing a logged-out page renders shows markdown, rich text or a code block; a hit means a
+ // PostHog AI tool card component became a static import.
+ 'src/lib/lemon-ui/LemonMarkdown/',
+ 'src/lib/components/RichContentEditor/',
+ 'src/lib/components/CodeSnippet/',
+ // The taxonomy JSON is a quarter-MiB lookup table for the property editors, not for /login.
+ 'src/taxonomy/core-filter-definitions-by-group.json',
],
},
{
root: 'src/scenes/AuthenticatedShell.tsx',
label: 'authenticated shell (every logged-in page)',
- // 2026-09-03: 7.64 MiB eager output after moving DASHBOARD_WIDGET_PREVIEWS out of the
- // widget catalog and importing MathAvailability from ActionFilterRow/types instead of the
- // component. ~15% headroom so routine churn doesn't trip the warn.
- budgetBytes: 9_200_000,
+ // 2026-09-11: 8.27 MiB eager output = 6.91 MiB JS (2688 files) + the 1.36 MiB linked
+ // stylesheet. ~15% headroom so routine churn doesn't trip the warn.
+ budgetBytes: 9_970_000,
forbidden: [
'node_modules/monaco-editor/',
'src/lib/components/ActivityLog/describers',
@@ -260,6 +265,10 @@ function eagerChunkClosure(entry) {
return seen
}
+// The page links only the src/index.tsx entry's stylesheet (writePreloadManifest in build.mjs). esbuild
+// gives other chunks a `cssBundle` too, but the browser never downloads those files.
+const linkedStylesheet = outputs[entryChunk('src/index.tsx')]?.cssBundle
+
const summaryLines = ['## Eager graph check', '', '| Root | Eager size | Budget | Files |', '| --- | --- | --- | --- |']
const report = { roots: [], errors: [], warnings: [] }
@@ -312,25 +321,19 @@ for (const { root: rootSpec, label, budgetBytes, forbidden } of ROOTS) {
// Attribute each input module the bytes it actually contributes to the eager chunks —
// tree-shaken modules contribute nothing, so a barrel only counts its used exports.
const eagerBytesByFile = new Map()
- const cssBundlesSeen = new Set()
let totalBytes = 0
for (const chunk of eagerChunks) {
totalBytes += outputs[chunk].bytes
- // esbuild attaches a JS chunk's stylesheet via `cssBundle`, not an `imports` edge, so
- // the chunk walk never reaches it — but it's downloaded before render, so count each
- // distinct eager stylesheet once. Without this, adding a large eager .scss moves real
- // bytes onto the critical path while the metric stays flat.
- const cssBundle = outputs[chunk].cssBundle
- if (cssBundle && !cssBundlesSeen.has(cssBundle)) {
- cssBundlesSeen.add(cssBundle)
- totalBytes += outputs[cssBundle]?.bytes || 0
- }
for (const [file, info] of Object.entries(outputs[chunk].inputs || {})) {
if (info.bytesInOutput > 0) {
eagerBytesByFile.set(file, (eagerBytesByFile.get(file) || 0) + info.bytesInOutput)
}
}
}
+ // `cssBundle` is not an `imports` edge, so the chunk walk never reaches the sheet every page links.
+ if (linkedStylesheet) {
+ totalBytes += outputs[linkedStylesheet].bytes
+ }
const largest = [...eagerBytesByFile.entries()].sort((a, b) => b[1] - a[1]).slice(0, 15)
const overBudget = totalBytes > budgetBytes
diff --git a/frontend/src/lib/utils/eventUsageLogic.ts b/frontend/src/lib/utils/eventUsageLogic.ts
index fd7146a3d1c7..2553ce38b27b 100644
--- a/frontend/src/lib/utils/eventUsageLogic.ts
+++ b/frontend/src/lib/utils/eventUsageLogic.ts
@@ -47,7 +47,6 @@ import {
isTrendsQuery,
queryUsesDataWarehouse,
} from '~/queries/utils'
-import { PROPERTY_KEYS } from '~/taxonomy/taxonomy'
import {
ChartDisplayType,
CohortType,
@@ -3350,6 +3349,9 @@ export const eventUsageLogic = kea<eventUsageLogicType>([
breakpoint
) => {
await breakpoint(500)
+ // Not a module-scope import: the taxonomy JSON is a quarter-MiB table and this logic boots every page.
+ const { PROPERTY_KEYS } = await import('~/taxonomy/taxonomy')
+ breakpoint()
let custom_properties_count = 0
let posthog_properties_count = 0
diff --git a/frontend/src/loadPostHogJS.test.ts b/frontend/src/loadPostHogJS.test.ts
new file mode 100644
index 000000000000..12d3860c87a9
--- /dev/null
+++ b/frontend/src/loadPostHogJS.test.ts
@@ -0,0 +1,12 @@
+import { sampleOnProperty } from 'posthog-js/lib/src/extensions/sampling'
+
+import { isInDeferredInitSample } from './loadPostHogJS'
+
+describe('isInDeferredInitSample', () => {
+ it.each(['', 'a', '0198f1e2-9c3b-7a1d-8f4e-2b6c9d0e1f23', 'session-one', 'session-two', 'session-three'])(
+ 'keeps the posthog-js sampling verdict for session %p',
+ (sessionId) => {
+ expect(isInDeferredInitSample(sessionId)).toBe(sampleOnProperty(sessionId, 0.5))
+ }
+ )
+})
diff --git a/frontend/src/loadPostHogJS.tsx b/frontend/src/loadPostHogJS.tsx
index ee56d763e895..521ddc5a6024 100644
--- a/frontend/src/loadPostHogJS.tsx
+++ b/frontend/src/loadPostHogJS.tsx
@@ -1,5 +1,4 @@
import posthog, { BeforeSendFn, PostHogInterface, SessionRecordingOptions } from 'posthog-js'
-import { sampleOnProperty } from 'posthog-js/lib/src/extensions/sampling'
import { FEATURE_FLAGS } from 'lib/constants'
import { isOAuthMode } from 'lib/oauth/oauthClient'
@@ -10,9 +9,15 @@ import { startFramerateTracking } from './framerateTracker'
export const SDK_DEFAULTS_DATE = '2026-05-30'
-const shouldDefer = (): boolean => {
- const sessionId = posthog.get_session_id()
- return sampleOnProperty(sessionId, 0.5)
+// The same hash as posthog-js's own `sampleOnProperty`, so existing sessions keep their side of the
+// split. Inlined because the deep import of that extension ships a second copy of @posthog/core.
+export function isInDeferredInitSample(sessionId: string): boolean {
+ let hash = 0
+ for (let i = 0; i < sessionId.length; i++) {
+ hash = (hash << 5) - hash + sessionId.charCodeAt(i)
+ hash |= 0
+ }
+ return Math.abs(hash) % 100 < 50
}
const shouldTrackFramerate = (loadedInstance: PostHogInterface): boolean => {
@@ -52,7 +57,7 @@ export function loadPostHogJS(options: LoadPostHogJSOptions = {}): void {
disable_surveys: window.IMPERSONATED_SESSION,
disable_product_tours: true,
opt_out_capturing_by_default: window.IMPERSONATED_SESSION,
- __preview_deferred_init_extensions: shouldDefer(),
+ __preview_deferred_init_extensions: isInDeferredInitSample(posthog.get_session_id()),
error_tracking: {
__capturePostHogExceptions: true,
},