Improved draw_children performance
This commit is contained in:
+226
-226
@@ -1,227 +1,227 @@
|
||||
Iterx72,Nestingx72,Time µs
|
||||
14,14,42234
|
||||
0,8,622
|
||||
1,13,3648
|
||||
8,7,17692
|
||||
10,6,22069
|
||||
0,5,747
|
||||
3,9,7241
|
||||
11,0,650
|
||||
5,6,11514
|
||||
3,6,7085
|
||||
12,0,647
|
||||
14,13,30158
|
||||
13,7,27962
|
||||
0,3,952
|
||||
11,10,24479
|
||||
4,13,9140
|
||||
11,7,24296
|
||||
1,9,9842
|
||||
14,8,29822
|
||||
4,5,9477
|
||||
8,10,17455
|
||||
7,6,15619
|
||||
8,3,17578
|
||||
3,5,7325
|
||||
6,8,13457
|
||||
8,6,20035
|
||||
6,1,13401
|
||||
9,10,19662
|
||||
13,2,29492
|
||||
2,5,5608
|
||||
12,7,26234
|
||||
1,5,2805
|
||||
1,4,2885
|
||||
8,11,17593
|
||||
8,9,17500
|
||||
1,6,2753
|
||||
12,11,26755
|
||||
6,5,13467
|
||||
0,0,1422
|
||||
2,10,4962
|
||||
9,2,20309
|
||||
10,11,21396
|
||||
10,12,21635
|
||||
12,1,26076
|
||||
1,8,4557
|
||||
11,3,24812
|
||||
6,14,13990
|
||||
11,8,24085
|
||||
13,9,28520
|
||||
2,9,5434
|
||||
12,8,26119
|
||||
9,8,19384
|
||||
13,5,28750
|
||||
11,9,24372
|
||||
1,14,3759
|
||||
12,6,26656
|
||||
0,14,561
|
||||
13,4,28078
|
||||
10,5,21794
|
||||
1,11,3352
|
||||
7,14,15201
|
||||
5,5,11773
|
||||
14,1,30065
|
||||
14,11,30285
|
||||
7,9,15836
|
||||
11,14,24824
|
||||
4,8,9150
|
||||
6,9,13543
|
||||
14,4,30374
|
||||
7,3,15286
|
||||
8,5,21031
|
||||
6,3,13330
|
||||
10,7,21641
|
||||
2,0,858
|
||||
3,12,6860
|
||||
5,14,11219
|
||||
7,8,15480
|
||||
13,12,28471
|
||||
5,10,11089
|
||||
3,13,7204
|
||||
2,2,5540
|
||||
9,12,19704
|
||||
3,3,7137
|
||||
4,2,9135
|
||||
10,2,21296
|
||||
13,6,27789
|
||||
14,6,30623
|
||||
4,7,9092
|
||||
9,4,20170
|
||||
11,13,25349
|
||||
7,5,16132
|
||||
1,12,3646
|
||||
2,14,4875
|
||||
1,3,2748
|
||||
5,8,11319
|
||||
6,11,13043
|
||||
8,1,17858
|
||||
10,8,21873
|
||||
9,9,19614
|
||||
11,11,25009
|
||||
1,1,2799
|
||||
6,7,13485
|
||||
9,14,19574
|
||||
0,2,848
|
||||
2,1,6248
|
||||
8,2,17396
|
||||
8,8,17922
|
||||
9,7,20009
|
||||
1,7,2707
|
||||
2,7,4816
|
||||
2,13,4955
|
||||
11,2,23803
|
||||
12,2,26388
|
||||
13,3,28983
|
||||
0,10,623
|
||||
14,3,30537
|
||||
5,11,11324
|
||||
7,13,15644
|
||||
10,13,21916
|
||||
13,8,28073
|
||||
14,5,30794
|
||||
0,12,567
|
||||
14,12,29804
|
||||
2,4,5408
|
||||
2,8,5015
|
||||
3,14,7076
|
||||
2,3,5556
|
||||
5,12,11445
|
||||
6,6,13404
|
||||
11,5,23340
|
||||
4,1,9139
|
||||
12,5,27242
|
||||
12,4,26856
|
||||
3,4,7263
|
||||
5,13,11218
|
||||
4,3,9138
|
||||
4,6,9116
|
||||
14,7,30699
|
||||
8,13,17633
|
||||
3,2,7138
|
||||
9,0,656
|
||||
11,4,23580
|
||||
7,2,15523
|
||||
0,9,559
|
||||
2,11,4915
|
||||
7,12,15596
|
||||
3,1,7032
|
||||
4,9,9686
|
||||
3,7,6856
|
||||
11,12,24834
|
||||
14,10,30028
|
||||
14,9,30361
|
||||
10,3,22041
|
||||
7,1,15353
|
||||
10,10,21820
|
||||
5,3,11101
|
||||
14,2,30052
|
||||
13,13,27454
|
||||
9,6,19744
|
||||
12,13,26535
|
||||
13,11,28255
|
||||
10,0,648
|
||||
5,1,11501
|
||||
7,7,15633
|
||||
8,12,17515
|
||||
4,10,9326
|
||||
7,0,668
|
||||
10,4,21791
|
||||
10,1,21700
|
||||
13,10,28381
|
||||
14,0,647
|
||||
9,1,19943
|
||||
1,0,795
|
||||
2,6,5429
|
||||
11,1,23689
|
||||
5,2,11336
|
||||
10,14,26278
|
||||
6,12,13255
|
||||
13,1,32857
|
||||
14,14,29719
|
||||
12,10,26924
|
||||
7,4,15464
|
||||
4,0,658
|
||||
0,13,564
|
||||
0,7,630
|
||||
0,1,1045
|
||||
9,13,19476
|
||||
8,0,662
|
||||
3,11,7193
|
||||
0,4,736
|
||||
9,11,19490
|
||||
6,0,652
|
||||
6,13,13460
|
||||
1,2,2691
|
||||
6,10,13237
|
||||
9,5,19720
|
||||
3,10,7132
|
||||
12,3,25963
|
||||
3,0,660
|
||||
6,4,13314
|
||||
0,6,651
|
||||
4,12,9023
|
||||
5,4,11549
|
||||
5,9,10991
|
||||
9,3,20006
|
||||
4,11,9322
|
||||
11,6,24139
|
||||
13,0,926
|
||||
12,9,26827
|
||||
6,2,13309
|
||||
0,11,562
|
||||
7,11,15718
|
||||
12,12,27386
|
||||
2,12,4871
|
||||
7,10,15838
|
||||
10,9,24169
|
||||
5,0,687
|
||||
8,14,17760
|
||||
13,14,28126
|
||||
8,4,17665
|
||||
12,14,41734
|
||||
5,7,11572
|
||||
4,4,9382
|
||||
1,10,3374
|
||||
4,14,9428
|
||||
3,8,7031
|
||||
14,14,12797
|
||||
14,12,11775
|
||||
1,5,1413
|
||||
4,4,3773
|
||||
14,9,11790
|
||||
1,6,1364
|
||||
9,2,7869
|
||||
0,6,658
|
||||
6,1,5264
|
||||
13,7,11002
|
||||
3,5,2904
|
||||
6,2,5217
|
||||
9,6,7804
|
||||
14,10,11650
|
||||
8,10,7484
|
||||
8,4,7097
|
||||
11,5,9290
|
||||
10,2,8451
|
||||
0,3,818
|
||||
10,11,8478
|
||||
7,9,6120
|
||||
5,4,4454
|
||||
12,12,11135
|
||||
9,13,7693
|
||||
1,3,1370
|
||||
7,3,6016
|
||||
1,9,1362
|
||||
13,6,10852
|
||||
12,1,10057
|
||||
7,5,6434
|
||||
11,11,9395
|
||||
0,4,718
|
||||
5,11,4543
|
||||
8,6,7230
|
||||
13,10,11024
|
||||
6,4,5464
|
||||
14,0,648
|
||||
5,8,4812
|
||||
5,2,4877
|
||||
9,14,7750
|
||||
13,3,10860
|
||||
3,14,2977
|
||||
10,7,8500
|
||||
5,7,4498
|
||||
2,8,2172
|
||||
14,4,11521
|
||||
3,3,2953
|
||||
10,4,8542
|
||||
4,11,3705
|
||||
3,6,2935
|
||||
12,2,10065
|
||||
7,2,6218
|
||||
1,14,1366
|
||||
8,3,6908
|
||||
0,2,949
|
||||
12,11,10240
|
||||
9,1,7942
|
||||
13,12,11014
|
||||
2,6,2166
|
||||
1,8,1372
|
||||
2,9,2157
|
||||
4,2,3742
|
||||
11,14,9328
|
||||
12,9,10376
|
||||
6,14,5787
|
||||
0,1,1139
|
||||
13,1,10823
|
||||
6,6,5260
|
||||
13,13,11246
|
||||
1,7,1395
|
||||
0,14,530
|
||||
2,7,2194
|
||||
3,9,2985
|
||||
14,5,11736
|
||||
14,6,11742
|
||||
5,14,4436
|
||||
9,7,7881
|
||||
6,10,5276
|
||||
6,11,5353
|
||||
4,8,3743
|
||||
1,0,744
|
||||
10,14,8673
|
||||
4,3,3786
|
||||
8,11,7193
|
||||
9,0,659
|
||||
11,3,9316
|
||||
8,12,6900
|
||||
6,3,5313
|
||||
5,5,4484
|
||||
8,1,7013
|
||||
3,11,2952
|
||||
4,1,3693
|
||||
8,8,6802
|
||||
9,3,7787
|
||||
6,0,677
|
||||
10,3,8730
|
||||
3,8,3035
|
||||
8,5,7176
|
||||
7,8,6104
|
||||
3,1,2946
|
||||
2,11,2174
|
||||
3,13,2974
|
||||
3,2,2957
|
||||
2,4,2193
|
||||
14,3,11935
|
||||
14,11,11743
|
||||
7,4,6073
|
||||
0,9,524
|
||||
11,6,9238
|
||||
4,14,3742
|
||||
7,7,6195
|
||||
3,10,3034
|
||||
0,7,606
|
||||
14,8,11580
|
||||
9,8,7825
|
||||
12,8,10017
|
||||
11,7,9449
|
||||
13,11,11607
|
||||
6,9,5274
|
||||
10,12,8370
|
||||
8,0,636
|
||||
8,2,7010
|
||||
0,13,535
|
||||
11,12,9348
|
||||
6,5,5280
|
||||
9,5,7846
|
||||
3,4,2927
|
||||
4,5,3766
|
||||
9,11,7779
|
||||
10,10,8455
|
||||
10,5,8521
|
||||
2,1,2207
|
||||
2,2,2150
|
||||
1,1,1527
|
||||
10,13,8667
|
||||
7,10,6194
|
||||
5,12,4485
|
||||
4,9,3764
|
||||
12,4,9852
|
||||
11,0,641
|
||||
4,12,3821
|
||||
12,3,10057
|
||||
11,2,9288
|
||||
5,0,637
|
||||
7,12,6402
|
||||
14,1,11986
|
||||
2,3,2141
|
||||
11,9,9388
|
||||
12,13,10279
|
||||
4,0,635
|
||||
7,6,6145
|
||||
7,11,6310
|
||||
0,10,527
|
||||
12,6,10391
|
||||
14,14,12297
|
||||
13,4,11124
|
||||
14,7,11840
|
||||
0,11,558
|
||||
10,8,8604
|
||||
4,13,3859
|
||||
5,13,4486
|
||||
0,12,522
|
||||
7,13,6051
|
||||
13,2,10971
|
||||
13,5,11374
|
||||
7,1,6133
|
||||
9,10,7755
|
||||
9,9,7747
|
||||
11,13,9282
|
||||
4,10,3737
|
||||
13,0,653
|
||||
5,6,4578
|
||||
4,6,3921
|
||||
4,7,3704
|
||||
10,0,642
|
||||
1,12,1362
|
||||
3,0,661
|
||||
3,7,2986
|
||||
10,1,8607
|
||||
10,6,8538
|
||||
11,8,9260
|
||||
5,3,4441
|
||||
14,13,11718
|
||||
5,10,4507
|
||||
6,8,5576
|
||||
12,5,10427
|
||||
6,7,5226
|
||||
12,7,10218
|
||||
5,1,4923
|
||||
9,12,8258
|
||||
8,9,7006
|
||||
2,0,650
|
||||
8,7,6943
|
||||
12,0,645
|
||||
2,5,2192
|
||||
7,14,6478
|
||||
11,1,9436
|
||||
10,9,8658
|
||||
1,4,1355
|
||||
2,13,2165
|
||||
1,11,1388
|
||||
3,12,2931
|
||||
2,10,2162
|
||||
7,0,638
|
||||
1,2,1384
|
||||
8,14,6945
|
||||
1,13,1349
|
||||
0,8,602
|
||||
8,13,7151
|
||||
6,12,5362
|
||||
11,4,9381
|
||||
12,14,10160
|
||||
13,9,10754
|
||||
5,9,4437
|
||||
0,5,694
|
||||
12,10,10466
|
||||
1,10,1362
|
||||
9,4,7532
|
||||
13,8,11058
|
||||
13,14,11414
|
||||
2,12,2166
|
||||
6,13,5332
|
||||
0,0,1190
|
||||
11,10,9264
|
||||
2,14,2172
|
||||
14,2,11901
|
||||
|
+37
-19
@@ -83,6 +83,10 @@ impl Context {
|
||||
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>(
|
||||
self: &Arc<Self>,
|
||||
handler: F,
|
||||
@@ -195,37 +199,51 @@ impl Context {
|
||||
}
|
||||
|
||||
pub fn draw_children(self: &Arc<Self>, ctx: &mut DrawContext) {
|
||||
let scope_count = self.scopes.access_ref().len();
|
||||
let shared_ctx = Arc::new(Mutex::new(ctx.clone()));
|
||||
let (tx_done, rx_done) = std::sync::mpsc::channel::<()>();
|
||||
let cmds: Arc<
|
||||
Mutex<
|
||||
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({
|
||||
let shared_ctx = shared_ctx.clone();
|
||||
let cmds = cmds.clone();
|
||||
move |scopes| {
|
||||
for scope in scopes {
|
||||
let shared_ctx = shared_ctx.clone();
|
||||
let tx_done = tx_done.clone();
|
||||
scope.access_children(move |children| {
|
||||
let mut c = shared_ctx.lock().unwrap();
|
||||
for (child, view_wrapper) in children {
|
||||
let view = child.get_view();
|
||||
if let Some(view_wrapper) = view_wrapper {
|
||||
view_wrapper(&mut c, view)
|
||||
} else {
|
||||
let area = c.area.clone();
|
||||
c.draw_view(area, view);
|
||||
scope.access_children({
|
||||
let cmds = cmds.clone();
|
||||
move |children| {
|
||||
for (child, view_wrapper) in children {
|
||||
let view_wrapper = view_wrapper.clone();
|
||||
let cmds = cmds.clone();
|
||||
child.access_view(move |view| {
|
||||
cmds.lock().unwrap().push((view_wrapper, view.clone()))
|
||||
});
|
||||
}
|
||||
}
|
||||
let _ = tx_done.send(());
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
for _ in 0..scope_count {
|
||||
rx_done.recv().expect("Failed receiving done signal");
|
||||
for (view_wrapper, view) in cmds.lock().unwrap().iter() {
|
||||
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> {
|
||||
|
||||
Reference in New Issue
Block a user