Improved draw_children performance

This commit is contained in:
2026-01-31 16:16:08 +01:00
parent 457b894864
commit 1f566e19e7
2 changed files with 263 additions and 245 deletions
+226 -226
View File
@@ -1,227 +1,227 @@
Iterx72,Nestingx72,Time µs Iterx72,Nestingx72,Time µs
14,14,42234 14,14,12797
0,8,622 14,12,11775
1,13,3648 1,5,1413
8,7,17692 4,4,3773
10,6,22069 14,9,11790
0,5,747 1,6,1364
3,9,7241 9,2,7869
11,0,650 0,6,658
5,6,11514 6,1,5264
3,6,7085 13,7,11002
12,0,647 3,5,2904
14,13,30158 6,2,5217
13,7,27962 9,6,7804
0,3,952 14,10,11650
11,10,24479 8,10,7484
4,13,9140 8,4,7097
11,7,24296 11,5,9290
1,9,9842 10,2,8451
14,8,29822 0,3,818
4,5,9477 10,11,8478
8,10,17455 7,9,6120
7,6,15619 5,4,4454
8,3,17578 12,12,11135
3,5,7325 9,13,7693
6,8,13457 1,3,1370
8,6,20035 7,3,6016
6,1,13401 1,9,1362
9,10,19662 13,6,10852
13,2,29492 12,1,10057
2,5,5608 7,5,6434
12,7,26234 11,11,9395
1,5,2805 0,4,718
1,4,2885 5,11,4543
8,11,17593 8,6,7230
8,9,17500 13,10,11024
1,6,2753 6,4,5464
12,11,26755 14,0,648
6,5,13467 5,8,4812
0,0,1422 5,2,4877
2,10,4962 9,14,7750
9,2,20309 13,3,10860
10,11,21396 3,14,2977
10,12,21635 10,7,8500
12,1,26076 5,7,4498
1,8,4557 2,8,2172
11,3,24812 14,4,11521
6,14,13990 3,3,2953
11,8,24085 10,4,8542
13,9,28520 4,11,3705
2,9,5434 3,6,2935
12,8,26119 12,2,10065
9,8,19384 7,2,6218
13,5,28750 1,14,1366
11,9,24372 8,3,6908
1,14,3759 0,2,949
12,6,26656 12,11,10240
0,14,561 9,1,7942
13,4,28078 13,12,11014
10,5,21794 2,6,2166
1,11,3352 1,8,1372
7,14,15201 2,9,2157
5,5,11773 4,2,3742
14,1,30065 11,14,9328
14,11,30285 12,9,10376
7,9,15836 6,14,5787
11,14,24824 0,1,1139
4,8,9150 13,1,10823
6,9,13543 6,6,5260
14,4,30374 13,13,11246
7,3,15286 1,7,1395
8,5,21031 0,14,530
6,3,13330 2,7,2194
10,7,21641 3,9,2985
2,0,858 14,5,11736
3,12,6860 14,6,11742
5,14,11219 5,14,4436
7,8,15480 9,7,7881
13,12,28471 6,10,5276
5,10,11089 6,11,5353
3,13,7204 4,8,3743
2,2,5540 1,0,744
9,12,19704 10,14,8673
3,3,7137 4,3,3786
4,2,9135 8,11,7193
10,2,21296 9,0,659
13,6,27789 11,3,9316
14,6,30623 8,12,6900
4,7,9092 6,3,5313
9,4,20170 5,5,4484
11,13,25349 8,1,7013
7,5,16132 3,11,2952
1,12,3646 4,1,3693
2,14,4875 8,8,6802
1,3,2748 9,3,7787
5,8,11319 6,0,677
6,11,13043 10,3,8730
8,1,17858 3,8,3035
10,8,21873 8,5,7176
9,9,19614 7,8,6104
11,11,25009 3,1,2946
1,1,2799 2,11,2174
6,7,13485 3,13,2974
9,14,19574 3,2,2957
0,2,848 2,4,2193
2,1,6248 14,3,11935
8,2,17396 14,11,11743
8,8,17922 7,4,6073
9,7,20009 0,9,524
1,7,2707 11,6,9238
2,7,4816 4,14,3742
2,13,4955 7,7,6195
11,2,23803 3,10,3034
12,2,26388 0,7,606
13,3,28983 14,8,11580
0,10,623 9,8,7825
14,3,30537 12,8,10017
5,11,11324 11,7,9449
7,13,15644 13,11,11607
10,13,21916 6,9,5274
13,8,28073 10,12,8370
14,5,30794 8,0,636
0,12,567 8,2,7010
14,12,29804 0,13,535
2,4,5408 11,12,9348
2,8,5015 6,5,5280
3,14,7076 9,5,7846
2,3,5556 3,4,2927
5,12,11445 4,5,3766
6,6,13404 9,11,7779
11,5,23340 10,10,8455
4,1,9139 10,5,8521
12,5,27242 2,1,2207
12,4,26856 2,2,2150
3,4,7263 1,1,1527
5,13,11218 10,13,8667
4,3,9138 7,10,6194
4,6,9116 5,12,4485
14,7,30699 4,9,3764
8,13,17633 12,4,9852
3,2,7138 11,0,641
9,0,656 4,12,3821
11,4,23580 12,3,10057
7,2,15523 11,2,9288
0,9,559 5,0,637
2,11,4915 7,12,6402
7,12,15596 14,1,11986
3,1,7032 2,3,2141
4,9,9686 11,9,9388
3,7,6856 12,13,10279
11,12,24834 4,0,635
14,10,30028 7,6,6145
14,9,30361 7,11,6310
10,3,22041 0,10,527
7,1,15353 12,6,10391
10,10,21820 14,14,12297
5,3,11101 13,4,11124
14,2,30052 14,7,11840
13,13,27454 0,11,558
9,6,19744 10,8,8604
12,13,26535 4,13,3859
13,11,28255 5,13,4486
10,0,648 0,12,522
5,1,11501 7,13,6051
7,7,15633 13,2,10971
8,12,17515 13,5,11374
4,10,9326 7,1,6133
7,0,668 9,10,7755
10,4,21791 9,9,7747
10,1,21700 11,13,9282
13,10,28381 4,10,3737
14,0,647 13,0,653
9,1,19943 5,6,4578
1,0,795 4,6,3921
2,6,5429 4,7,3704
11,1,23689 10,0,642
5,2,11336 1,12,1362
10,14,26278 3,0,661
6,12,13255 3,7,2986
13,1,32857 10,1,8607
14,14,29719 10,6,8538
12,10,26924 11,8,9260
7,4,15464 5,3,4441
4,0,658 14,13,11718
0,13,564 5,10,4507
0,7,630 6,8,5576
0,1,1045 12,5,10427
9,13,19476 6,7,5226
8,0,662 12,7,10218
3,11,7193 5,1,4923
0,4,736 9,12,8258
9,11,19490 8,9,7006
6,0,652 2,0,650
6,13,13460 8,7,6943
1,2,2691 12,0,645
6,10,13237 2,5,2192
9,5,19720 7,14,6478
3,10,7132 11,1,9436
12,3,25963 10,9,8658
3,0,660 1,4,1355
6,4,13314 2,13,2165
0,6,651 1,11,1388
4,12,9023 3,12,2931
5,4,11549 2,10,2162
5,9,10991 7,0,638
9,3,20006 1,2,1384
4,11,9322 8,14,6945
11,6,24139 1,13,1349
13,0,926 0,8,602
12,9,26827 8,13,7151
6,2,13309 6,12,5362
0,11,562 11,4,9381
7,11,15718 12,14,10160
12,12,27386 13,9,10754
2,12,4871 5,9,4437
7,10,15838 0,5,694
10,9,24169 12,10,10466
5,0,687 1,10,1362
8,14,17760 9,4,7532
13,14,28126 13,8,11058
8,4,17665 13,14,11414
12,14,41734 2,12,2166
5,7,11572 6,13,5332
4,4,9382 0,0,1190
1,10,3374 11,10,9264
4,14,9428 2,14,2172
3,8,7031 14,2,11901
1 Iterx72 Nestingx72 Time µs
2 14 14 42234 12797
3 0 14 8 12 622 11775
4 1 13 5 3648 1413
5 8 4 7 4 17692 3773
6 10 14 6 9 22069 11790
7 0 1 5 6 747 1364
8 3 9 9 2 7241 7869
9 11 0 0 6 650 658
10 5 6 6 1 11514 5264
11 3 13 6 7 7085 11002
12 12 3 0 5 647 2904
13 14 6 13 2 30158 5217
14 13 9 7 6 27962 7804
15 0 14 3 10 952 11650
16 11 8 10 24479 7484
17 4 8 13 4 9140 7097
18 11 7 5 24296 9290
19 1 10 9 2 9842 8451
20 14 0 8 3 29822 818
21 4 10 5 11 9477 8478
22 8 7 10 9 17455 6120
23 7 5 6 4 15619 4454
24 8 12 3 12 17578 11135
25 3 9 5 13 7325 7693
26 6 1 8 3 13457 1370
27 8 7 6 3 20035 6016
28 6 1 1 9 13401 1362
29 9 13 10 6 19662 10852
30 13 12 2 1 29492 10057
31 2 7 5 5608 6434
32 12 11 7 11 26234 9395
33 1 0 5 4 2805 718
34 1 5 4 11 2885 4543
35 8 11 6 17593 7230
36 8 13 9 10 17500 11024
37 1 6 6 4 2753 5464
38 12 14 11 0 26755 648
39 6 5 5 8 13467 4812
40 0 5 0 2 1422 4877
41 2 9 10 14 4962 7750
42 9 13 2 3 20309 10860
43 10 3 11 14 21396 2977
44 10 12 7 21635 8500
45 12 5 1 7 26076 4498
46 1 2 8 4557 2172
47 11 14 3 4 24812 11521
48 6 3 14 3 13990 2953
49 11 10 8 4 24085 8542
50 13 4 9 11 28520 3705
51 2 3 9 6 5434 2935
52 12 8 2 26119 10065
53 9 7 8 2 19384 6218
54 13 1 5 14 28750 1366
55 11 8 9 3 24372 6908
56 1 0 14 2 3759 949
57 12 6 11 26656 10240
58 0 9 14 1 561 7942
59 13 4 12 28078 11014
60 10 2 5 6 21794 2166
61 1 11 8 3352 1372
62 7 2 14 9 15201 2157
63 5 4 5 2 11773 3742
64 14 11 1 14 30065 9328
65 14 12 11 9 30285 10376
66 7 6 9 14 15836 5787
67 11 0 14 1 24824 1139
68 4 13 8 1 9150 10823
69 6 9 6 13543 5260
70 14 13 4 13 30374 11246
71 7 1 3 7 15286 1395
72 8 0 5 14 21031 530
73 6 2 3 7 13330 2194
74 10 3 7 9 21641 2985
75 2 14 0 5 858 11736
76 3 14 12 6 6860 11742
77 5 14 11219 4436
78 7 9 8 7 15480 7881
79 13 6 12 10 28471 5276
80 5 6 10 11 11089 5353
81 3 4 13 8 7204 3743
82 2 1 2 0 5540 744
83 9 10 12 14 19704 8673
84 3 4 3 7137 3786
85 4 8 2 11 9135 7193
86 10 9 2 0 21296 659
87 13 11 6 3 27789 9316
88 14 8 6 12 30623 6900
89 4 6 7 3 9092 5313
90 9 5 4 5 20170 4484
91 11 8 13 1 25349 7013
92 7 3 5 11 16132 2952
93 1 4 12 1 3646 3693
94 2 8 14 8 4875 6802
95 1 9 3 2748 7787
96 5 6 8 0 11319 677
97 6 10 11 3 13043 8730
98 8 3 1 8 17858 3035
99 10 8 8 5 21873 7176
100 9 7 9 8 19614 6104
101 11 3 11 1 25009 2946
102 1 2 1 11 2799 2174
103 6 3 7 13 13485 2974
104 9 3 14 2 19574 2957
105 0 2 2 4 848 2193
106 2 14 1 3 6248 11935
107 8 14 2 11 17396 11743
108 8 7 8 4 17922 6073
109 9 0 7 9 20009 524
110 1 11 7 6 2707 9238
111 2 4 7 14 4816 3742
112 2 7 13 7 4955 6195
113 11 3 2 10 23803 3034
114 12 0 2 7 26388 606
115 13 14 3 8 28983 11580
116 0 9 10 8 623 7825
117 14 12 3 8 30537 10017
118 5 11 11 7 11324 9449
119 7 13 13 11 15644 11607
120 10 6 13 9 21916 5274
121 13 10 8 12 28073 8370
122 14 8 5 0 30794 636
123 0 8 12 2 567 7010
124 14 0 12 13 29804 535
125 2 11 4 12 5408 9348
126 2 6 8 5 5015 5280
127 3 9 14 5 7076 7846
128 2 3 3 4 5556 2927
129 5 4 12 5 11445 3766
130 6 9 6 11 13404 7779
131 11 10 5 10 23340 8455
132 4 10 1 5 9139 8521
133 12 2 5 1 27242 2207
134 12 2 4 2 26856 2150
135 3 1 4 1 7263 1527
136 5 10 13 11218 8667
137 4 7 3 10 9138 6194
138 4 5 6 12 9116 4485
139 14 4 7 9 30699 3764
140 8 12 13 4 17633 9852
141 3 11 2 0 7138 641
142 9 4 0 12 656 3821
143 11 12 4 3 23580 10057
144 7 11 2 15523 9288
145 0 5 9 0 559 637
146 2 7 11 12 4915 6402
147 7 14 12 1 15596 11986
148 3 2 1 3 7032 2141
149 4 11 9 9686 9388
150 3 12 7 13 6856 10279
151 11 4 12 0 24834 635
152 14 7 10 6 30028 6145
153 14 7 9 11 30361 6310
154 10 0 3 10 22041 527
155 7 12 1 6 15353 10391
156 10 14 10 14 21820 12297
157 5 13 3 4 11101 11124
158 14 2 7 30052 11840
159 13 0 13 11 27454 558
160 9 10 6 8 19744 8604
161 12 4 13 26535 3859
162 13 5 11 13 28255 4486
163 10 0 0 12 648 522
164 5 7 1 13 11501 6051
165 7 13 7 2 15633 10971
166 8 13 12 5 17515 11374
167 4 7 10 1 9326 6133
168 7 9 0 10 668 7755
169 10 9 4 9 21791 7747
170 10 11 1 13 21700 9282
171 13 4 10 28381 3737
172 14 13 0 647 653
173 9 5 1 6 19943 4578
174 1 4 0 6 795 3921
175 2 4 6 7 5429 3704
176 11 10 1 0 23689 642
177 5 1 2 12 11336 1362
178 10 3 14 0 26278 661
179 6 3 12 7 13255 2986
180 13 10 1 32857 8607
181 14 10 14 6 29719 8538
182 12 11 10 8 26924 9260
183 7 5 4 3 15464 4441
184 4 14 0 13 658 11718
185 0 5 13 10 564 4507
186 0 6 7 8 630 5576
187 0 12 1 5 1045 10427
188 9 6 13 7 19476 5226
189 8 12 0 7 662 10218
190 3 5 11 1 7193 4923
191 0 9 4 12 736 8258
192 9 8 11 9 19490 7006
193 6 2 0 652 650
194 6 8 13 7 13460 6943
195 1 12 2 0 2691 645
196 6 2 10 5 13237 2192
197 9 7 5 14 19720 6478
198 3 11 10 1 7132 9436
199 12 10 3 9 25963 8658
200 3 1 0 4 660 1355
201 6 2 4 13 13314 2165
202 0 1 6 11 651 1388
203 4 3 12 9023 2931
204 5 2 4 10 11549 2162
205 5 7 9 0 10991 638
206 9 1 3 2 20006 1384
207 4 8 11 14 9322 6945
208 11 1 6 13 24139 1349
209 13 0 0 8 926 602
210 12 8 9 13 26827 7151
211 6 2 12 13309 5362
212 0 11 11 4 562 9381
213 7 12 11 14 15718 10160
214 12 13 12 9 27386 10754
215 2 5 12 9 4871 4437
216 7 0 10 5 15838 694
217 10 12 9 10 24169 10466
218 5 1 0 10 687 1362
219 8 9 14 4 17760 7532
220 13 14 8 28126 11058
221 8 13 4 14 17665 11414
222 12 2 14 12 41734 2166
223 5 6 7 13 11572 5332
224 4 0 4 0 9382 1190
225 1 11 10 3374 9264
226 4 2 14 9428 2172
227 3 14 8 2 7031 11901
+37 -19
View File
@@ -83,6 +83,10 @@ impl Context {
self.view.access_ref().clone() self.view.access_ref().clone()
} }
pub fn access_view(self: &Arc<Self>, f: impl FnOnce(&mut View) + Send + 'static) {
self.view.access(f)
}
pub fn on_event<T: Any + 'static, F: Fn(&Arc<Self>, &T) + Send + Sync + 'static>( pub fn on_event<T: Any + 'static, F: Fn(&Arc<Self>, &T) + Send + Sync + 'static>(
self: &Arc<Self>, self: &Arc<Self>,
handler: F, handler: F,
@@ -195,37 +199,51 @@ impl Context {
} }
pub fn draw_children(self: &Arc<Self>, ctx: &mut DrawContext) { pub fn draw_children(self: &Arc<Self>, ctx: &mut DrawContext) {
let scope_count = self.scopes.access_ref().len(); let cmds: Arc<
let shared_ctx = Arc::new(Mutex::new(ctx.clone())); Mutex<
let (tx_done, rx_done) = std::sync::mpsc::channel::<()>(); Vec<(
Option<
Arc<
dyn Fn(
&mut DrawContext,
Arc<dyn Fn(&mut DrawContext) + Send + Sync + 'static>,
) + Send
+ Sync,
>,
>,
Arc<dyn Fn(&mut DrawContext) + Send + Sync>,
)>,
>,
> = Arc::new(Mutex::new(Vec::new()));
self.scopes.access({ self.scopes.access({
let shared_ctx = shared_ctx.clone(); let cmds = cmds.clone();
move |scopes| { move |scopes| {
for scope in scopes { for scope in scopes {
let shared_ctx = shared_ctx.clone(); scope.access_children({
let tx_done = tx_done.clone(); let cmds = cmds.clone();
scope.access_children(move |children| { move |children| {
let mut c = shared_ctx.lock().unwrap(); for (child, view_wrapper) in children {
for (child, view_wrapper) in children { let view_wrapper = view_wrapper.clone();
let view = child.get_view(); let cmds = cmds.clone();
if let Some(view_wrapper) = view_wrapper { child.access_view(move |view| {
view_wrapper(&mut c, view) cmds.lock().unwrap().push((view_wrapper, view.clone()))
} else { });
let area = c.area.clone();
c.draw_view(area, view);
} }
} }
let _ = tx_done.send(());
}); });
} }
} }
}); });
for _ in 0..scope_count { for (view_wrapper, view) in cmds.lock().unwrap().iter() {
rx_done.recv().expect("Failed receiving done signal"); if let Some(wrapper) = view_wrapper {
wrapper(ctx, view.clone());
} else {
let area = ctx.area.clone();
ctx.draw_view(area, view.clone());
}
} }
*ctx = shared_ctx.lock().unwrap().clone();
} }
pub fn get_executor(self: &Arc<Self>) -> Arc<dyn CommandExecutor> { pub fn get_executor(self: &Arc<Self>) -> Arc<dyn CommandExecutor> {