Commit 1247380
authored
perf(maskeditor): read the brush container rect once per move, not per axis (#15384)
## Summary
`brushLeft` and `brushTop` in `BrushCursor.vue` each called
`containerRef.getBoundingClientRect()`. Both depend on
`store.cursorPoint`, which changes on every mousemove, so painting in
the mask editor cost **two forced synchronous layouts per pointer
event** to obtain one rect.
## The change
One `brushPosition` computed reads the rect once and returns both axes;
`brushLeft` and `brushTop` read from it.
## Why this is safe
The read stays inside a computed over `cursorPoint` deliberately. A
`DOMRect` is not reactive, so nothing would invalidate a cached one —
re-reading it as the cursor moves is precisely what keeps the offset
correct while the mask editor dialog is dragged or resized.
**So this changes how many reads happen, not when.** Dialog move and
resize behave exactly as before, which is what makes it reviewable
without an interactive pass over those paths.
## Tests
Added `should read the container rect once per position, not once per
axis`, which spies on the container's `getBoundingClientRect`. Verified
it fails on current `main`:
```
AssertionError: left and top come from the same rect; reading it twice is
two forced layouts per mousemove: expected "getBoundingClientRect" to be
called 1 times, but got 2 times
```
12 tests green, `oxfmt --check` and `oxlint` clean, `vue-tsc` reports
nothing on either file.
## Review focus
- The existing offset test (`should subtract container offset when
containerRef is provided`) still passes unchanged, which is the evidence
that positioning is untouched.
- If anyone wants the rect cached across moves instead, that is a
different and larger change: it needs a `ResizeObserver` plus a drag
hook on the dialog, and it would alter behaviour rather than cost.
Deliberately not attempted here.1 parent f9ec97a commit 1247380
2 files changed
Lines changed: 73 additions & 19 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
| 2 | + | |
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| |||
140 | 140 | | |
141 | 141 | | |
142 | 142 | | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
143 | 188 | | |
144 | 189 | | |
145 | 190 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
56 | 56 | | |
57 | 57 | | |
58 | 58 | | |
59 | | - | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
60 | 71 | | |
61 | | - | |
62 | | - | |
63 | | - | |
64 | | - | |
65 | | - | |
66 | | - | |
67 | | - | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
68 | 84 | | |
69 | 85 | | |
70 | | - | |
71 | | - | |
72 | | - | |
73 | | - | |
74 | | - | |
75 | | - | |
76 | | - | |
77 | | - | |
78 | | - | |
79 | | - | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
80 | 89 | | |
81 | 90 | | |
82 | 91 | | |
| |||
0 commit comments