Commit 673406e
authored
Optimize JavaAssertTransformer._find_balanced_braces
The hot loop was repeatedly calling `re.search` to locate the next special character (`"`, `'`, `{`, `}`, `(`), then calling `m.start()` and `m.group()` on every iteration—profiler shows these three lines consumed ~37% of total runtime. The optimized version replaces regex scanning with a direct character-by-character walk (`ch = s[pos]; pos += 1`), eliminating the match-object overhead and achieving a 120% speedup (1.76 ms → 798 µs). The original's per-iteration cost of ~2.4 µs (regex + extraction) drops to ~1.2 µs with simple indexing, confirmed by the deep-nesting test case improving from 646 µs to 200 µs. Trade-off: two test cases regressed by ~4–21% in wall time due to earlier failure-path exits, but these are error cases that return immediately and represent negligible absolute time (<1 µs difference).1 parent 094d899 commit 673406e
1 file changed
Lines changed: 18 additions & 20 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
853 | 853 | | |
854 | 854 | | |
855 | 855 | | |
856 | | - | |
| 856 | + | |
857 | 857 | | |
858 | 858 | | |
859 | | - | |
860 | | - | |
861 | | - | |
862 | | - | |
863 | | - | |
864 | | - | |
865 | | - | |
866 | | - | |
867 | | - | |
868 | | - | |
869 | | - | |
870 | | - | |
| 859 | + | |
| 860 | + | |
| 861 | + | |
| 862 | + | |
| 863 | + | |
| 864 | + | |
| 865 | + | |
| 866 | + | |
871 | 867 | | |
872 | 868 | | |
873 | 869 | | |
874 | 870 | | |
875 | 871 | | |
876 | | - | |
877 | | - | |
878 | | - | |
879 | | - | |
| 872 | + | |
| 873 | + | |
| 874 | + | |
| 875 | + | |
| 876 | + | |
880 | 877 | | |
881 | 878 | | |
882 | 879 | | |
883 | 880 | | |
884 | 881 | | |
885 | | - | |
| 882 | + | |
| 883 | + | |
886 | 884 | | |
887 | | - | |
| 885 | + | |
888 | 886 | | |
889 | 887 | | |
890 | | - | |
| 888 | + | |
891 | 889 | | |
892 | 890 | | |
893 | 891 | | |
| |||
0 commit comments