From 89161ab39b247baaa49ffdd0884bee347091442e Mon Sep 17 00:00:00 2001 From: Leo dev Date: Sat, 31 Jan 2026 15:46:59 +0100 Subject: [PATCH 1/6] Fixed draw_children --- src/component/context.rs | 45 +++++++++++++++++++++++----------------- 1 file changed, 26 insertions(+), 19 deletions(-) diff --git a/src/component/context.rs b/src/component/context.rs index de08664..28e19e0 100644 --- a/src/component/context.rs +++ b/src/component/context.rs @@ -195,30 +195,37 @@ impl Context { } pub fn draw_children(self: &Arc, ctx: &mut DrawContext) { - let c = ctx.clone(); + 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 (tx, rx) = std::sync::mpsc::channel::(); - - self.scopes.access(move |scopes| { - for scope in scopes { - let mut c = c.clone(); - let tx = tx.clone(); - scope.access_children(move |children| { - for (child, view_wrapper) in children { - let view = child.get_view(); - - if let Some(view_wrapper) = view_wrapper { - view_wrapper(&mut c, view) - } else { - c.draw_view(c.area.clone(), view); + self.scopes.access({ + let shared_ctx = shared_ctx.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); + } } - } - tx.send(c.clone()).expect("Failed transmitting DrawContext"); - }); + let _ = tx_done.send(()); + }); + } } }); - *ctx = rx.recv().expect("Failed receiving DrawContext"); + for _ in 0..scope_count { + rx_done.recv().expect("Failed receiving done signal"); + } + *ctx = shared_ctx.lock().unwrap().clone(); } pub fn get_executor(self: &Arc) -> Arc { From 457b894864ac0fe78f0a91318c3347732f35741d Mon Sep 17 00:00:00 2001 From: Leo dev Date: Sat, 31 Jan 2026 15:48:21 +0100 Subject: [PATCH 2/6] Benchmark --- benchmark.csv | 452 +++++++++++++++++++++++++------------------------- 1 file changed, 226 insertions(+), 226 deletions(-) diff --git a/benchmark.csv b/benchmark.csv index 65d5940..aad5bd1 100644 --- a/benchmark.csv +++ b/benchmark.csv @@ -1,227 +1,227 @@ Iterx72,Nestingx72,Time µs -14,14,14236 -11,8,10608 -8,13,7793 -13,7,12073 -11,6,10495 -5,2,5135 -6,12,6144 -6,3,6341 -12,7,11304 -11,5,10622 -0,9,497 -3,2,3303 -5,1,5186 -10,8,9781 -1,11,1358 -2,9,2341 -10,11,9788 -14,5,13036 -9,1,8807 -4,12,4249 -8,1,8306 -14,4,12985 -5,0,419 -4,13,4234 -10,1,9793 -3,13,3255 -0,4,625 -7,6,7066 -8,12,7954 -10,12,9876 -8,11,8015 -6,8,6104 -0,11,514 -2,10,2373 -8,2,7891 -2,14,2337 -2,13,2337 -7,12,7006 -3,10,3300 -11,10,10772 -4,5,4299 -10,14,9909 -12,5,11532 -9,10,8809 -12,12,11954 -14,11,13452 -8,8,7965 -4,0,449 -5,6,5127 -7,8,6921 -4,4,4244 -1,10,1370 -5,9,5122 -1,7,1369 -0,3,844 -8,3,7937 -9,9,8777 -13,6,12476 -9,3,8961 -2,5,2368 -1,12,1363 -5,12,5075 -13,11,12363 -6,13,5963 -0,8,484 -2,12,2370 -8,5,7946 -14,9,13504 -12,1,11839 -12,2,11601 -2,6,2329 -10,10,9602 -7,3,6970 -14,6,13394 -0,7,628 -6,9,6100 -12,13,11391 -0,12,458 -1,14,1370 -12,10,11719 -9,8,8807 -4,7,4235 -1,0,462 -3,11,3538 -11,7,10786 -11,13,10710 -11,2,10394 -3,9,3315 -4,6,4174 -13,8,12538 -9,11,8710 -12,14,11814 -13,2,12647 -8,7,8019 -3,1,3287 -4,8,4591 -4,3,4197 -6,10,5985 -5,7,5171 -12,9,11579 -10,4,9714 -12,4,11811 -2,3,2391 -8,9,7997 -9,7,8853 -11,1,10700 -11,11,10798 -13,4,12644 -6,4,6290 -6,2,5916 -2,0,427 -2,8,2355 -10,2,9637 -6,5,6069 -6,11,6048 -12,11,11921 -9,4,8754 -5,4,5111 -13,10,12518 -8,14,7837 -5,8,5127 -8,10,8085 -0,2,1028 -2,1,2400 -0,13,408 -6,14,6027 -12,8,11785 -2,2,2326 -1,2,1394 -4,1,4251 -1,1,1446 -3,0,433 -10,13,9693 -9,0,432 -1,3,1441 -9,13,8858 -9,14,8795 -11,9,10632 -12,0,417 -7,1,7013 -6,1,6097 -10,7,10114 -10,9,9876 -10,5,9802 -2,4,2363 -11,12,10781 -11,14,10677 -3,7,3262 -6,7,6201 -4,9,4380 -3,8,3345 -13,9,12485 -0,14,419 -1,6,1347 -4,2,4216 -4,14,4209 -7,9,6976 -13,0,458 -0,1,361 -5,14,5204 -14,2,13169 -5,10,5096 -1,5,1370 -8,0,431 -6,6,6031 -8,4,7809 -9,12,11983 -3,4,3276 -12,6,11921 -6,0,485 -1,13,1375 -4,11,4237 -0,10,481 -13,13,12545 -14,12,13253 -3,5,3210 -5,5,5158 -7,7,6992 -5,11,5076 -7,13,7056 -11,3,10584 -3,3,3302 -14,13,13280 -13,3,12771 -14,0,429 -7,5,7065 -7,14,6952 -8,6,7835 -2,7,2334 -2,11,2367 -11,4,10606 -7,11,6845 -14,8,13736 -0,5,844 -1,9,1333 -10,6,9721 -9,6,8769 -7,10,6998 -10,3,9810 -14,7,13311 -14,14,13481 -11,0,426 -5,3,5102 -1,4,1457 -13,14,12431 -12,3,11717 -13,5,12523 -14,10,13457 -0,6,705 -3,14,3335 -13,12,12714 -7,4,6951 -3,6,3247 -9,5,8713 -3,12,3401 -14,1,13199 -4,10,4260 -10,0,428 -5,13,5103 -0,0,421 -14,3,13070 -9,2,8816 -7,0,451 -7,2,6974 -1,8,1363 -13,1,12699 \ No newline at end of file +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 \ No newline at end of file From 1f566e19e75bfc0fa4b682a11ddd5d9a28a6c583 Mon Sep 17 00:00:00 2001 From: Leo dev Date: Sat, 31 Jan 2026 16:16:08 +0100 Subject: [PATCH 3/6] Improved draw_children performance --- benchmark.csv | 452 +++++++++++++++++++-------------------- src/component/context.rs | 56 +++-- 2 files changed, 263 insertions(+), 245 deletions(-) diff --git a/benchmark.csv b/benchmark.csv index aad5bd1..cdeedb6 100644 --- a/benchmark.csv +++ b/benchmark.csv @@ -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 \ No newline at end of file +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 \ No newline at end of file diff --git a/src/component/context.rs b/src/component/context.rs index 28e19e0..9348245 100644 --- a/src/component/context.rs +++ b/src/component/context.rs @@ -83,6 +83,10 @@ impl Context { self.view.access_ref().clone() } + pub fn access_view(self: &Arc, f: impl FnOnce(&mut View) + Send + 'static) { + self.view.access(f) + } + pub fn on_event, &T) + Send + Sync + 'static>( self: &Arc, handler: F, @@ -195,37 +199,51 @@ impl Context { } pub fn draw_children(self: &Arc, 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, + ) + Send + + Sync, + >, + >, + Arc, + )>, + >, + > = 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) -> Arc { From 04f2abc47a31faecd4728f62217aa7083fc9d2c8 Mon Sep 17 00:00:00 2001 From: Leo dev Date: Sat, 31 Jan 2026 17:45:14 +0100 Subject: [PATCH 4/6] Made scope back to Mutex due to performance --- benchmark.csv | 450 +++++++++++++++++++-------------------- macros/src/emit.rs | 16 +- src/component/context.rs | 97 ++------- src/component/scope.rs | 31 +-- 4 files changed, 260 insertions(+), 334 deletions(-) diff --git a/benchmark.csv b/benchmark.csv index cdeedb6..c263e60 100644 --- a/benchmark.csv +++ b/benchmark.csv @@ -1,227 +1,227 @@ Iterx72,Nestingx72,Time µs -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 +14,14,15500 +0,8,534 +9,0,635 +11,4,2921 +9,4,2321 +9,2,2328 +2,7,963 +4,3,1326 +6,12,2494 +14,8,3317 +12,12,2926 +8,0,614 +10,9,2530 +0,5,713 +4,12,1354 +8,2,2136 +10,5,2519 +14,4,3311 +14,14,3368 +12,4,2938 +14,2,3273 +2,12,929 +9,3,2354 +1,1,786 +12,13,2884 +4,9,1336 +5,9,1557 +3,6,1153 +0,12,556 +13,6,3336 +3,10,1130 +7,0,617 +7,11,1919 +0,0,1501 +0,1,1112 +5,2,1637 +11,3,2713 +1,11,725 +7,5,1934 +4,11,1353 +3,1,1140 +10,12,2524 +14,3,3316 +8,11,2144 +0,7,633 +11,8,2741 +2,3,968 +3,8,1121 +12,14,3113 +13,1,3096 +13,4,3106 +14,11,3297 +1,2,708 +13,3,3090 +6,4,1747 +11,11,2740 +10,8,2567 +7,7,1936 +4,6,1349 +3,7,1149 +1,7,750 +10,3,2585 +12,0,615 +10,13,2584 +3,9,1186 +14,10,3393 +2,4,943 +13,5,3090 +14,0,610 +5,14,1528 +11,6,2764 +14,13,3268 +13,2,3105 +4,7,1375 +0,2,824 +13,13,3093 +6,7,1742 +2,2,941 +8,1,2165 +11,0,614 +12,5,2971 +4,5,1337 +7,8,1923 +7,3,2124 +10,1,2513 +1,10,715 +2,8,935 +7,14,1940 +5,5,1543 +1,6,720 +8,10,2144 +6,8,1729 +13,14,3127 +10,0,613 +2,0,616 +5,13,1568 +8,5,2157 +7,4,1947 +7,13,1957 +9,5,2323 +0,3,895 +0,11,549 +14,7,3303 +8,6,2171 +10,10,2521 +14,12,3344 +4,10,1362 +6,14,1758 +1,3,723 +7,12,1940 +4,0,614 +11,7,2727 +6,11,2908 +3,14,1136 +13,8,3496 +12,10,2962 +2,9,925 +2,5,936 +9,6,2371 +5,6,1567 +2,10,935 +9,7,2340 +4,14,1328 +1,12,720 +8,12,2132 +6,9,15000 +8,8,2293 +9,1,2364 +2,14,965 +12,8,2909 +11,12,2750 +13,0,628 +13,12,3124 +1,8,710 +3,4,1133 +12,9,2927 +14,1,3317 +3,5,1140 +8,7,2149 +7,2,2000 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 \ No newline at end of file +10,2,2515 +11,5,2834 +9,14,2347 +2,6,927 +9,9,2348 +13,7,3137 +4,1,1462 +11,2,2736 +5,11,1535 +11,14,2751 +12,11,2899 +5,10,1559 +12,7,2915 +5,12,1551 +3,12,1138 +11,1,2719 +11,13,2736 +6,6,1787 +5,3,1552 +8,4,2128 +1,5,721 +4,4,1357 +3,2,1136 +4,8,1326 +1,13,723 +14,5,3505 +6,0,607 +12,6,2897 +6,5,1706 +14,6,3357 +8,3,2194 +6,3,1762 +5,4,1613 +0,10,522 +7,9,1954 +11,9,2745 +3,11,1132 +5,0,620 +6,13,2016 +8,13,2146 +13,11,3138 +13,10,3120 +11,10,2789 +0,13,536 +1,9,718 +13,9,3090 +10,11,2511 +12,2,2937 +7,10,1909 +7,6,1929 +5,7,1573 +1,14,747 +10,7,2584 +3,13,1137 +0,14,525 +10,4,2534 +7,1,1978 +5,1,1583 +8,9,2130 +12,1,2913 +5,8,1538 +6,10,6557 +10,6,2528 +2,1,929 +3,0,610 +2,13,930 +6,1,1751 +9,8,2468 +6,2,1725 +4,2,1400 +8,14,2143 +12,3,2950 +1,0,633 +9,10,2374 +3,3,1132 +10,14,2509 +0,4,964 +9,11,2337 +4,13,1376 +0,6,596 +1,4,733 +9,13,2363 +14,9,3278 +2,11,916 +9,12,2339 \ No newline at end of file diff --git a/macros/src/emit.rs b/macros/src/emit.rs index bd31d80..60884ca 100644 --- a/macros/src/emit.rs +++ b/macros/src/emit.rs @@ -76,15 +76,13 @@ fn emit_node_scope(node: &RsxNode) -> TokenStream { { #deps_emit r.dynamic_scope(move |scope| { - scope.access_children(|children| { - if #cond { - if children.is_empty() { - #(#kids)* - } - } else { - .children.clear(); + if #cond { + if scope.children.lock().unwrap().is_empty() { + #(#kids)* } - }) + } else { + scope.children.lock().unwrap().clear(); + } }, #deps_vec_emit); } } @@ -105,7 +103,7 @@ fn emit_node_scope(node: &RsxNode) -> TokenStream { #deps_emit #[allow(unused_parens)] r.dynamic_scope(move |scope| { - scope.access_children(|children| children.clear()); + scope.children.lock().unwrap().clear(); for #pat in #expr { #(#kids)* } diff --git a/src/component/context.rs b/src/component/context.rs index 9348245..636cf5f 100644 --- a/src/component/context.rs +++ b/src/component/context.rs @@ -20,7 +20,7 @@ pub struct Context { component: AccessCell, view: AccessCell, event_handlers: AccessCell>>, - scopes: AccessCell>>, + pub(crate) scopes: Mutex>>, executor: Arc, } @@ -33,7 +33,7 @@ impl Context { component: AccessCell::new(Arc::new(component)), view: AccessCell::new(Arc::new(|_| {})), event_handlers: AccessCell::new(HashMap::new()), - scopes: AccessCell::new(Vec::new()), + scopes: Mutex::new(Vec::new()), executor, }) } @@ -83,10 +83,6 @@ impl Context { self.view.access_ref().clone() } - pub fn access_view(self: &Arc, f: impl FnOnce(&mut View) + Send + 'static) { - self.view.access(f) - } - pub fn on_event, &T) + Send + Sync + 'static>( self: &Arc, handler: F, @@ -115,16 +111,11 @@ impl Context { (h.lock().unwrap())(self, event.as_ref()); } - self.scopes.access(move |scopes| { - for scope in scopes { - let event = event.clone(); - scope.access_children(move |children| { - for (child, _) in children { - child.emit_event(event.clone()); - } - }); + for scope in self.scopes.lock().unwrap().iter() { + for (child, _) in scope.children.lock().unwrap().iter() { + child.emit_event(event.clone()); } - }); + } } pub fn emit_event_threaded( @@ -143,26 +134,16 @@ impl Context { }); } - let event = event.clone(); - self.scopes.access(move |scopes| { - for scope in scopes { - let event = event.clone(); - scope.access_children(move |children| { - for (child, _) in children { - child.emit_event_threaded(&event); - } - }); + for scope in self.scopes.lock().unwrap().iter() { + for (child, _) in scope.children.lock().unwrap().iter() { + child.emit_event_threaded(event); } - }); + } } pub fn scope(self: &Arc) -> Arc { let scope = Scope::new(self.executor.clone()); - - self.scopes.access({ - let scope = scope.clone(); - move |scopes| scopes.push(scope) - }); + self.scopes.lock().unwrap().push(scope.clone()); scope } @@ -173,11 +154,7 @@ impl Context { dependencies: &[&dyn HookDependency], ) -> Arc { let scope = Scope::new(self.executor.clone()); - - self.scopes.access({ - let scope = scope.clone(); - move |scopes| scopes.push(scope) - }); + self.scopes.lock().unwrap().push(scope.clone()); drawer(&scope); @@ -195,54 +172,20 @@ impl Context { } pub fn add_scope(self: &Arc, scope: Arc) { - self.scopes.access(|scopes| scopes.push(scope)); + self.scopes.lock().unwrap().push(scope); } pub fn draw_children(self: &Arc, ctx: &mut DrawContext) { - let cmds: Arc< - Mutex< - Vec<( - Option< - Arc< - dyn Fn( - &mut DrawContext, - Arc, - ) + Send - + Sync, - >, - >, - Arc, - )>, - >, - > = Arc::new(Mutex::new(Vec::new())); + for scope in self.scopes.lock().unwrap().iter() { + for (child, view_wrapper) in scope.children.lock().unwrap().iter() { + let view = child.get_view(); - self.scopes.access({ - let cmds = cmds.clone(); - move |scopes| { - for scope in scopes { - 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())) - }); - } - } - }); + if let Some(view_wrapper) = view_wrapper { + view_wrapper(ctx, view) + } else { + ctx.draw_view(ctx.area.clone(), view); } } - }); - - 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()); - } } } diff --git a/src/component/scope.rs b/src/component/scope.rs index 83201ce..6cfe6e5 100644 --- a/src/component/scope.rs +++ b/src/component/scope.rs @@ -1,19 +1,18 @@ -use super::{context::Context, ComponentImpl}; -use crate::{engine::CommandExecutor, View, ViewWrapper}; -use access_cell::AccessCell; -use std::sync::Arc; +use std::sync::{Arc, Mutex}; -pub type ScopeChildren = Vec<(Arc, Option)>; +use crate::{engine::CommandExecutor, View, ViewWrapper}; + +use super::{context::Context, ComponentImpl}; pub struct Scope { - children: AccessCell, + pub children: Mutex, Option)>>, executor: Arc, } impl Scope { pub fn new(executor: Arc) -> Arc { Arc::new(Self { - children: AccessCell::new(Vec::new()), + children: Mutex::new(Vec::new()), executor, }) } @@ -27,8 +26,7 @@ impl Scope { ctx.refresh(); - self.children - .access(|children| children.push((ctx, view_wrapper))); + self.children.lock().unwrap().push((ctx, view_wrapper)); } pub fn view(self: &Arc, view: View) { @@ -36,19 +34,6 @@ impl Scope { ctx.refresh(); - self.children.access(|children| children.push((ctx, None))); - } - - pub fn view_wrapper(self: &Arc, view: View, view_wrapper: Option) { - let ctx = Context::new(view, self.executor.clone()); - - ctx.refresh(); - - self.children - .access(|children| children.push((ctx, view_wrapper))); - } - - pub fn access_children(self: &Arc, f: impl FnOnce(&mut ScopeChildren) + Send + 'static) { - self.children.access(f); + self.children.lock().unwrap().push((ctx, None)); } } From 8ebef0680809ebd0f6095d4d0ec9d88e5c0c55c6 Mon Sep 17 00:00:00 2001 From: Leo dev Date: Sat, 31 Jan 2026 17:47:08 +0100 Subject: [PATCH 5/6] Benchmark --- benchmark.csv | 452 +++++++++++++++++++++++++------------------------- 1 file changed, 226 insertions(+), 226 deletions(-) diff --git a/benchmark.csv b/benchmark.csv index c263e60..50f08bb 100644 --- a/benchmark.csv +++ b/benchmark.csv @@ -1,227 +1,227 @@ Iterx72,Nestingx72,Time µs -14,14,15500 -0,8,534 -9,0,635 -11,4,2921 -9,4,2321 -9,2,2328 -2,7,963 -4,3,1326 -6,12,2494 -14,8,3317 -12,12,2926 -8,0,614 -10,9,2530 -0,5,713 -4,12,1354 -8,2,2136 -10,5,2519 -14,4,3311 -14,14,3368 -12,4,2938 -14,2,3273 -2,12,929 -9,3,2354 -1,1,786 -12,13,2884 -4,9,1336 -5,9,1557 -3,6,1153 -0,12,556 -13,6,3336 -3,10,1130 -7,0,617 -7,11,1919 -0,0,1501 -0,1,1112 -5,2,1637 -11,3,2713 -1,11,725 -7,5,1934 -4,11,1353 -3,1,1140 -10,12,2524 -14,3,3316 -8,11,2144 -0,7,633 -11,8,2741 -2,3,968 -3,8,1121 -12,14,3113 -13,1,3096 -13,4,3106 -14,11,3297 -1,2,708 -13,3,3090 -6,4,1747 -11,11,2740 -10,8,2567 -7,7,1936 -4,6,1349 -3,7,1149 -1,7,750 -10,3,2585 -12,0,615 -10,13,2584 -3,9,1186 -14,10,3393 -2,4,943 -13,5,3090 -14,0,610 -5,14,1528 -11,6,2764 -14,13,3268 -13,2,3105 -4,7,1375 -0,2,824 -13,13,3093 -6,7,1742 -2,2,941 -8,1,2165 -11,0,614 -12,5,2971 -4,5,1337 -7,8,1923 -7,3,2124 -10,1,2513 -1,10,715 -2,8,935 -7,14,1940 -5,5,1543 -1,6,720 -8,10,2144 -6,8,1729 -13,14,3127 -10,0,613 -2,0,616 -5,13,1568 -8,5,2157 -7,4,1947 -7,13,1957 -9,5,2323 -0,3,895 -0,11,549 -14,7,3303 -8,6,2171 -10,10,2521 -14,12,3344 -4,10,1362 -6,14,1758 -1,3,723 -7,12,1940 -4,0,614 -11,7,2727 -6,11,2908 -3,14,1136 -13,8,3496 -12,10,2962 -2,9,925 -2,5,936 -9,6,2371 -5,6,1567 -2,10,935 -9,7,2340 -4,14,1328 -1,12,720 -8,12,2132 -6,9,15000 -8,8,2293 -9,1,2364 -2,14,965 -12,8,2909 -11,12,2750 -13,0,628 -13,12,3124 -1,8,710 -3,4,1133 -12,9,2927 -14,1,3317 -3,5,1140 -8,7,2149 -7,2,2000 -0,9,524 -10,2,2515 -11,5,2834 -9,14,2347 -2,6,927 -9,9,2348 -13,7,3137 -4,1,1462 -11,2,2736 -5,11,1535 -11,14,2751 -12,11,2899 -5,10,1559 -12,7,2915 -5,12,1551 -3,12,1138 -11,1,2719 -11,13,2736 -6,6,1787 -5,3,1552 -8,4,2128 -1,5,721 -4,4,1357 -3,2,1136 -4,8,1326 -1,13,723 -14,5,3505 -6,0,607 -12,6,2897 -6,5,1706 -14,6,3357 -8,3,2194 -6,3,1762 -5,4,1613 -0,10,522 -7,9,1954 -11,9,2745 -3,11,1132 -5,0,620 -6,13,2016 -8,13,2146 -13,11,3138 -13,10,3120 -11,10,2789 -0,13,536 -1,9,718 -13,9,3090 -10,11,2511 -12,2,2937 -7,10,1909 -7,6,1929 -5,7,1573 -1,14,747 -10,7,2584 -3,13,1137 -0,14,525 -10,4,2534 -7,1,1978 -5,1,1583 -8,9,2130 -12,1,2913 -5,8,1538 -6,10,6557 -10,6,2528 -2,1,929 -3,0,610 -2,13,930 -6,1,1751 -9,8,2468 -6,2,1725 -4,2,1400 -8,14,2143 -12,3,2950 -1,0,633 -9,10,2374 -3,3,1132 -10,14,2509 -0,4,964 -9,11,2337 -4,13,1376 -0,6,596 -1,4,733 -9,13,2363 -14,9,3278 -2,11,916 -9,12,2339 \ No newline at end of file +14,14,11964 +0,1,1078 +5,8,1818 +10,13,2632 +14,2,3392 +0,9,520 +9,3,2360 +10,5,2551 +10,11,2548 +6,8,1738 +12,12,2922 +0,8,601 +12,4,2919 +0,11,521 +6,4,1942 +11,7,2741 +9,4,2496 +5,9,1764 +13,9,3069 +2,5,1053 +5,11,1790 +14,1,3581 +5,0,962 +0,3,845 +1,3,868 +7,8,2013 +12,3,2987 +9,8,2328 +10,7,2533 +11,1,2766 +7,1,1938 +0,5,687 +6,9,1830 +10,14,2628 +6,12,1786 +4,0,835 +4,14,2464 +10,1,2633 +12,7,2948 +2,9,1066 +4,6,2646 +7,11,1999 +5,13,1748 +13,4,3110 +13,13,3094 +3,5,1166 +11,12,2745 +1,2,814 +9,5,2419 +2,11,1117 +1,13,835 +11,11,2759 +1,12,882 +9,1,2457 +0,6,680 +5,12,1794 +9,11,2326 +10,9,2546 +10,10,2604 +13,2,3250 +13,7,3113 +7,10,1959 +1,14,833 +6,6,1886 +14,7,3339 +6,7,1824 +11,6,2756 +12,6,3007 +14,6,3315 +4,3,11464 +2,14,924 +7,12,1966 +11,14,2817 +9,10,2367 +1,11,827 +8,14,2184 +14,0,643 +11,3,2781 +2,4,1123 +12,8,2950 +13,6,3160 +3,13,1289 +7,7,1989 +3,9,1142 +3,6,1168 +4,8,2788 +14,12,3346 +1,1,805 +5,10,1781 +7,13,1988 +5,5,2015 +0,14,520 +11,8,2890 +3,10,1140 +13,10,3235 +3,14,1185 +8,10,2183 +12,10,2896 +2,8,1072 +9,6,2358 +13,1,3066 +3,8,1133 +11,10,2758 +4,13,2550 +1,0,643 +4,2,5482 +3,7,1155 +1,4,726 +3,3,1192 +4,11,2576 +8,0,619 +9,2,2444 +10,3,2581 +4,5,5400 +5,3,2444 +1,10,804 +10,2,2563 +0,7,592 +0,2,802 +1,5,741 +2,7,984 +10,0,755 +13,14,3112 +5,14,1811 +8,12,2180 +6,11,1723 +4,7,2897 +10,8,2536 +1,7,813 +6,0,699 +8,2,2187 +5,7,1811 +14,8,3304 +2,0,661 +8,13,2185 +1,9,786 +3,0,623 +12,5,3012 +8,1,2203 +8,11,2285 +14,10,3413 +4,10,2613 +11,5,2729 +6,1,2035 +12,1,2891 +5,4,2036 +2,3,1083 +14,3,3312 +3,2,1278 +5,2,2392 +8,7,2151 +5,6,2072 +3,12,1230 +2,10,954 +2,13,932 +13,8,3128 +0,12,521 +11,4,2769 +7,2,1947 +4,1,1802 +8,8,2163 +7,3,1966 +13,3,3207 +1,8,746 +12,9,2955 +10,12,2570 +9,9,2388 +4,12,2566 +7,0,619 +7,9,2004 +13,0,607 +14,9,3355 +3,4,1154 +11,2,2753 +11,13,2739 +6,13,1735 +7,6,1983 +8,3,2166 +7,14,1958 +6,2,2101 +13,5,3221 +8,4,2120 +10,4,2716 +14,5,3264 +14,13,3299 +11,9,2725 +13,11,3132 +1,6,809 +2,2,1155 +4,4,2242 +8,6,2218 +12,0,645 +7,4,1925 +2,6,1054 +9,13,2340 +13,12,3112 +14,4,3334 +3,11,1139 +12,14,3004 +4,9,2649 +0,13,527 +12,11,2976 +0,0,1559 +12,13,2952 +6,10,1749 +14,11,3365 +11,0,647 +2,12,1024 +10,6,2562 +8,5,2227 +9,12,2363 +2,1,1023 +0,10,528 +6,3,2005 +8,9,2195 +7,5,1966 +6,14,1755 +9,0,608 +14,14,3389 +9,7,2391 +0,4,688 +5,1,2574 +9,14,2353 +12,2,2975 +3,1,1276 +6,5,1804 \ No newline at end of file From dc2810b6d83309173d3b0dbf47de0e1848f90b7f Mon Sep 17 00:00:00 2001 From: Leo dev Date: Sat, 31 Jan 2026 17:48:25 +0100 Subject: [PATCH 6/6] Readme update #40 --- README.md | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 4b28b99..e20e2dc 100644 --- a/README.md +++ b/README.md @@ -17,21 +17,23 @@

- OSUI is a customizable terminal user interface (TUI) library written in Rust. It provides a set of components and rsx to build interactive command-line interfaces with ease. + OSUI is a customizable terminal user interface (TUI) library written in Rust.

```rust use osui::prelude::*; -fn main() -> std::io::Result<()> { - let screen = Screen::new(); +pub fn main() { + let engine = Console::new(); + engine.run(App {}).expect("Failed to run engine"); +} +#[component] +fn App(cx: &Arc) -> View { rsx! { - "Hello, World" + "Hello World" } - .draw(&screen); - - screen.run() + .view(&cx) } ```