Commit d850933
authored
[js] Reduce GC pressure in TypeScript getAttribute and isDisplayed atoms (#17582)
* [js] Reduce GC pressure in TypeScript getAttribute and isDisplayed atoms
getAttribute: convert BOOLEAN_PROPERTIES from Array to Set for O(1) .has()
lookup instead of O(n) .indexOf(), and call element.getAttribute(name)
directly at the three call sites that already hold the lowercased name,
avoiding a redundant .toLowerCase() in the wrapper.
isDisplayed: replace findImageUsingMap's full-DOM getElementsByTagName('*')
scan with a single querySelector('[usemap="#..."]') call, using the same
CSS attribute-value escaping pattern applied to nameMany in find-elements.
* [js] Memoize computed style, client rect, and displayed in isDisplayed atom
Add three per-call Maps inside isShownElement, scoped to the single
synchronous invocation so there is no stale-data risk and no GC pressure
between calls:
- computedStyleCache: getEffectiveStyle now fetches getComputedStyle once
per element and reuses the CSSStyleDeclaration for subsequent property
reads. A typical isShown call queries 5-8 properties on the same element.
- clientRectCache: getClientRect caches the Rect after the first
getBoundingClientRect (or imageMap rect) computation. Overflow checking
and positiveSize both query ancestor rects, so shared containers are
only laid out once.
- displayedCache: displayed() walks the full ancestor chain on every call.
positiveSize iterates all children calling displayedFn on each, so
shared ancestors were re-walked N times for N siblings. The cache makes
each ancestor node free after the first traversal.
* [js] Remove bogus async boolean-property test
document.createElement('script').async returns true by default (browser
sets the 'force async' flag on script elements created via JS), so the
test expecting null was never correct. The absent-boolean-returns-null
behaviour is already covered by the existing disabled and readonly tests.1 parent 62f911a commit d850933
4 files changed
Lines changed: 122 additions & 43 deletions
File tree
- javascript/atoms
- test
- typescript
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
182 | 182 | | |
183 | 183 | | |
184 | 184 | | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
185 | 197 | | |
186 | 198 | | |
187 | 199 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
124 | 124 | | |
125 | 125 | | |
126 | 126 | | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 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 | + | |
127 | 171 | | |
128 | 172 | | |
129 | 173 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
24 | | - | |
| 24 | + | |
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
| |||
68 | 68 | | |
69 | 69 | | |
70 | 70 | | |
71 | | - | |
| 71 | + | |
72 | 72 | | |
73 | 73 | | |
74 | 74 | | |
| |||
160 | 160 | | |
161 | 161 | | |
162 | 162 | | |
163 | | - | |
164 | | - | |
| 163 | + | |
| 164 | + | |
165 | 165 | | |
166 | 166 | | |
167 | 167 | | |
168 | 168 | | |
169 | 169 | | |
170 | | - | |
| 170 | + | |
171 | 171 | | |
172 | 172 | | |
173 | 173 | | |
| |||
179 | 179 | | |
180 | 180 | | |
181 | 181 | | |
182 | | - | |
| 182 | + | |
183 | 183 | | |
184 | 184 | | |
185 | 185 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
48 | 55 | | |
49 | 56 | | |
50 | 57 | | |
| |||
81 | 88 | | |
82 | 89 | | |
83 | 90 | | |
84 | | - | |
85 | | - | |
86 | | - | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
87 | 96 | | |
88 | | - | |
89 | 97 | | |
90 | 98 | | |
91 | 99 | | |
| |||
124 | 132 | | |
125 | 133 | | |
126 | 134 | | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
127 | 141 | | |
128 | 142 | | |
129 | | - | |
130 | | - | |
131 | | - | |
132 | | - | |
133 | | - | |
134 | | - | |
135 | | - | |
136 | | - | |
137 | | - | |
138 | | - | |
139 | | - | |
140 | | - | |
141 | | - | |
142 | | - | |
143 | | - | |
144 | | - | |
145 | | - | |
146 | | - | |
147 | | - | |
148 | | - | |
149 | | - | |
150 | | - | |
151 | | - | |
152 | | - | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
153 | 167 | | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
154 | 171 | | |
155 | 172 | | |
156 | 173 | | |
| |||
187 | 204 | | |
188 | 205 | | |
189 | 206 | | |
190 | | - | |
191 | | - | |
192 | | - | |
193 | | - | |
194 | | - | |
195 | | - | |
196 | | - | |
197 | | - | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
198 | 210 | | |
199 | 211 | | |
200 | 212 | | |
| |||
459 | 471 | | |
460 | 472 | | |
461 | 473 | | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
462 | 479 | | |
463 | 480 | | |
464 | 481 | | |
465 | 482 | | |
| 483 | + | |
466 | 484 | | |
467 | 485 | | |
468 | 486 | | |
469 | 487 | | |
470 | 488 | | |
471 | 489 | | |
472 | 490 | | |
| 491 | + | |
473 | 492 | | |
474 | 493 | | |
475 | 494 | | |
476 | 495 | | |
477 | 496 | | |
478 | 497 | | |
| 498 | + | |
479 | 499 | | |
480 | 500 | | |
481 | 501 | | |
482 | 502 | | |
| 503 | + | |
483 | 504 | | |
484 | 505 | | |
485 | 506 | | |
486 | | - | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
487 | 510 | | |
488 | 511 | | |
489 | 512 | | |
| |||
0 commit comments