From 51559fbefa91b616399d1b9ffe194df6f7eeec68 Mon Sep 17 00:00:00 2001 From: Dixing Xu Date: Sat, 31 Oct 2026 07:16:40 +0000 Subject: [PATCH] perf(compiler): 2.8x faster optimize_assembly Strip and uppercase each line once and keep the result in lists that all passes reuse. Check each line only against the rule for its opcode, and return early when no line starts with a rule opcode. Rule 6 still compares the original text, and the five-pass limit is unchanged. The benchmark based on test_compiler_for_loop_and_break takes 39% less time (138.75 ms -> 83.95 ms). On the loop/break test program, optimize_assembly alone goes from 87.5 us to 30.7 us. Co-Authored-By: Aiden --- src/tiny8/compiler.py | 150 +++++++++++++++++++++++------------------- 1 file changed, 83 insertions(+), 67 deletions(-) diff --git a/src/tiny8/compiler.py b/src/tiny8/compiler.py index 214b6ff..fd2d73e 100644 --- a/src/tiny8/compiler.py +++ b/src/tiny8/compiler.py @@ -903,112 +903,128 @@ def optimize_assembly(lines: list[str]) -> list[str]: - Removing redundant LD R16, R30 immediately after ST R30, R16 - Removing JMP