From b363fee510a048b010480ca7941126b8613fa6df Mon Sep 17 00:00:00 2001 From: fangliquan Date: Mon, 17 Aug 2026 02:59:08 +0800 Subject: [PATCH] perf(tui): skip cached rounding subtrees before descent --- .../src/native-ts/yoga-layout/index.ts | 16 +++++++++------- .../native-ts/yoga-layout/round-layout.test.ts | 2 +- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/ui-tui/packages/hermes-ink/src/native-ts/yoga-layout/index.ts b/ui-tui/packages/hermes-ink/src/native-ts/yoga-layout/index.ts index 5e954e9903..2333931237 100644 --- a/ui-tui/packages/hermes-ink/src/native-ts/yoga-layout/index.ts +++ b/ui-tui/packages/hermes-ink/src/native-ts/yoga-layout/index.ts @@ -979,13 +979,6 @@ function layoutNode( if (performLayout) { node._rLayoutGen = _generation - - let ancestor: Node | null = node - - while (ancestor && ancestor._rSubtreeLayoutGen !== _generation) { - ancestor._rSubtreeLayoutGen = _generation - ancestor = ancestor.parent - } } const style = node.style @@ -1056,6 +1049,15 @@ function layoutNode( } } + if (performLayout) { + let ancestor: Node | null = node + + while (ancestor && ancestor._rSubtreeLayoutGen !== _generation) { + ancestor._rSubtreeLayoutGen = _generation + ancestor = ancestor.parent + } + } + const wasDirty = node.isDirty_ if (performLayout) { diff --git a/ui-tui/packages/hermes-ink/src/native-ts/yoga-layout/round-layout.test.ts b/ui-tui/packages/hermes-ink/src/native-ts/yoga-layout/round-layout.test.ts index f49d787967..12f7b35927 100644 --- a/ui-tui/packages/hermes-ink/src/native-ts/yoga-layout/round-layout.test.ts +++ b/ui-tui/packages/hermes-ink/src/native-ts/yoga-layout/round-layout.test.ts @@ -74,7 +74,7 @@ describe('incremental layout rounding', () => { expect(clock.getComputedWidth()).toBe(6.5) expect(transcript.getComputedWidth()).toBe(transcriptWidth) expect(counters.rounded).toBeLessThanOrEqual(4) - expect(counters.roundSkips).toBeGreaterThanOrEqual(1) + expect(counters.roundSkips).toBe(1) root.freeRecursive() Yoga.Config.destroy(config)