perf(theme): keep NewDimmer inlinable by reading DimByAttribute in Dim
- commit
- a6e1848bcadd7214b5e13c29cab125be14d64d7b
- author
- brice · · 2026-10-03 14:02 UTC
- committer
- brice · · 2026-10-03 14:14 UTC
- parent
- 3703ae2
- signature
- GPG Verified
CD88F9E564E0102646FB6077A1A07C7C7C3E349D· arch-gpg Verified for the committer email
1 file · +6 -3
M internal/usecase/theme/theme.go +6 -3
| @@ -418,7 +418,6 @@ const defaultDimmingPercent = 35 | |||
| 418 | 418 | // Dimmer transforms resolved terminal colors for subdued UI states. Construct | |
| 419 | 419 | // it once and reuse it while rendering cells with the same theme and policy. | |
| 420 | 420 | type Dimmer struct { | |
| 421 | - | attribute bool | |
| 422 | 421 | theme Theme | |
| 423 | 422 | backgroundPercent int | |
| 424 | 423 | foregroundPercent int | |
| @@ -448,9 +447,13 @@ func WithForegroundDimming(percent int) DimmerOption { | |||
| 448 | 447 | } | |
| 449 | 448 | ||
| 450 | 449 | // NewDimmer returns a reusable dimmer with optional per-channel overrides. | |
| 450 | + | // | |
| 451 | + | // Keep this function inlinable: it sits on the per-cell render path, and adding | |
| 452 | + | // fields or work pushes it over the inline budget (80). After changing it, | |
| 453 | + | // check `go build -gcflags=-m=2 ./internal/usecase/theme 2>&1 | grep NewDimmer` | |
| 454 | + | // and rerun BenchmarkComposeCapturedFrame in internal/usecase/daemon. | |
| 451 | 455 | func NewDimmer(t Theme, opts ...DimmerOption) Dimmer { | |
| 452 | 456 | d := Dimmer{ | |
| 453 | - | attribute: t.DimByAttribute, | |
| 454 | 457 | theme: t, | |
| 455 | 458 | backgroundPercent: defaultDimmingPercent, | |
| 456 | 459 | foregroundPercent: defaultDimmingPercent, | |
| @@ -471,7 +474,7 @@ func NewDimmer(t Theme, opts ...DimmerOption) Dimmer { | |||
| 471 | 474 | // Dim fades a style's resolved background toward the terminal background, | |
| 472 | 475 | // then fades its foreground and custom underline toward that dimmed background. | |
| 473 | 476 | func (d Dimmer) Dim(style renderer.Style) renderer.Style { | |
| 474 | - | if d.attribute { | |
| 477 | + | if d.theme.DimByAttribute { | |
| 475 | 478 | style.Attrs |= renderer.AttrDim | |
| 476 | 479 | return style | |
| 477 | 480 | } | |
| @@ -418,7 +418,6 @@ const defaultDimmingPercent = 35 | |||||
| 418 | // Dimmer transforms resolved terminal colors for subdued UI states. Construct | 418 | // Dimmer transforms resolved terminal colors for subdued UI states. Construct | ||
| 419 | // it once and reuse it while rendering cells with the same theme and policy. | 419 | // it once and reuse it while rendering cells with the same theme and policy. | ||
| 420 | type Dimmer struct { | 420 | type Dimmer struct { | ||
| 421 | - | attribute bool | |||
| 422 | theme Theme | 421 | theme Theme | ||
| 423 | backgroundPercent int | 422 | backgroundPercent int | ||
| 424 | foregroundPercent int | 423 | foregroundPercent int | ||
| @@ -448,9 +447,13 @@ func WithForegroundDimming(percent int) DimmerOption { | |||||
| 448 | } | 447 | } | ||
| 449 | 448 | ||||
| 450 | // NewDimmer returns a reusable dimmer with optional per-channel overrides. | 449 | // NewDimmer returns a reusable dimmer with optional per-channel overrides. | ||
| 450 | + | // | |||
| 451 | + | // Keep this function inlinable: it sits on the per-cell render path, and adding | |||
| 452 | + | // fields or work pushes it over the inline budget (80). After changing it, | |||
| 453 | + | // check `go build -gcflags=-m=2 ./internal/usecase/theme 2>&1 | grep NewDimmer` | |||
| 454 | + | // and rerun BenchmarkComposeCapturedFrame in internal/usecase/daemon. | |||
| 451 | func NewDimmer(t Theme, opts ...DimmerOption) Dimmer { | 455 | func NewDimmer(t Theme, opts ...DimmerOption) Dimmer { | ||
| 452 | d := Dimmer{ | 456 | d := Dimmer{ | ||
| 453 | - | attribute: t.DimByAttribute, | |||
| 454 | theme: t, | 457 | theme: t, | ||
| 455 | backgroundPercent: defaultDimmingPercent, | 458 | backgroundPercent: defaultDimmingPercent, | ||
| 456 | foregroundPercent: defaultDimmingPercent, | 459 | foregroundPercent: defaultDimmingPercent, | ||
| @@ -471,7 +474,7 @@ func NewDimmer(t Theme, opts ...DimmerOption) Dimmer { | |||||
| 471 | // Dim fades a style's resolved background toward the terminal background, | 474 | // Dim fades a style's resolved background toward the terminal background, | ||
| 472 | // then fades its foreground and custom underline toward that dimmed background. | 475 | // then fades its foreground and custom underline toward that dimmed background. | ||
| 473 | func (d Dimmer) Dim(style renderer.Style) renderer.Style { | 476 | func (d Dimmer) Dim(style renderer.Style) renderer.Style { | ||
| 474 | - | if d.attribute { | 477 | + | if d.theme.DimByAttribute { |
| 475 | style.Attrs |= renderer.AttrDim | 478 | style.Attrs |= renderer.AttrDim | ||
| 476 | return style | 479 | return style | ||
| 477 | } | 480 | } | ||