Skip to content

Reuse BorderDrawable's paths and dash effects across draws - #60569

Open
ide wants to merge 1 commit into
react:mainfrom
expo:@ide/border-drawable-reuse
Open

ide wants to merge 1 commit into
react:mainfrom
expo:@ide/border-drawable-reuse

Conversation

@ide

@ide ide commented Dec 4, 2026

Copy link
Copy Markdown
Contributor

Summary:

BorderDrawable allocated a Path on every draw of a single-color rectangular border and a DashPathEffect for every edge of a dashed or dotted border on every draw. Each time it rebuilt the paths of a rounded border, it also built an outline path that nothing reads. It now keeps the single-border path, replaces the dash effect only when the border style or width changes, and no longer builds the outline path.

Changelog:

[INTERNAL] [CHANGED] - Reuse BorderDrawable's paths and dash effects across draws.

Test Plan:

BorderDrawableTest passes, including new checks that an unchanged dashed border draws with the same path and dash effect and that a width change replaces the effect. Both checks fail without this change.

On an arm64 Android 16 emulator, a benchmark in RNTester's Release build recorded one border into a RenderNode per draw, with both versions of BorderDrawable in one process, alternating which ran first, over three rounds of 21 samples:

Border Before After
1px, one color 595–721 ns, 164 B 405–555 ns, 66 B
2px, dashed 1,480–1,594 ns, 606 B 425–528 ns, 66 B
1px, rounded, after invalidateSelf() 1,448–1,685 ns, 623 B 1,177–1,320 ns, 442 B

The bytes are Java heap allocated per draw, including the RenderNode recording. A rounded border drawn again without invalidation takes the same time and allocation in both versions.

`BorderDrawable` allocated a `Path` on every draw of a single-color rectangular border and a `DashPathEffect` for every edge of a dashed or dotted border on every draw. Each time it rebuilt the paths of a rounded border, it also built an outline path that nothing reads. It now keeps the single-border path, replaces the dash effect only when the border style or width changes, and no longer builds the outline path.

`BorderDrawableTest` passes, including new checks that an unchanged dashed border draws with the same path and dash effect and that a width change replaces the effect. Both checks fail without this change.

On an arm64 Android 16 emulator, a benchmark in RNTester's Release build recorded one border into a `RenderNode` per draw, with both versions of `BorderDrawable` in one process, alternating which ran first, over three rounds of 21 samples:

| Border | Before | After |
| --- | --- | --- |
| 1px, one color | 595–721 ns, 164 B | 405–555 ns, 66 B |
| 2px, dashed | 1,480–1,594 ns, 606 B | 425–528 ns, 66 B |
| 1px, rounded, after `invalidateSelf()` | 1,448–1,685 ns, 623 B | 1,177–1,320 ns, 442 B |

The bytes are Java heap allocated per draw, including the `RenderNode` recording. A rounded border drawn again without invalidation takes the same time and allocation in both versions.

Signed-off-by: James Ide <ide@expo.dev>
@github-actions github-actions Bot added the Meta Review Required This PR is considered risky and requires Meta to import it to do more testing before merging. label Dec 4, 2026
@github-actions

github-actions Bot commented Dec 4, 2026

Copy link
Copy Markdown

Visual regression

No visual differences at 86f2fa41d4f2.

ios: no capture

@ide
ide marked this pull request as ready for review December 4, 2026 19:36

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Meta Review Required This PR is considered risky and requires Meta to import it to do more testing before merging.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant