Commit a8119b9
authored
Optimize CodeflashConfig.to_pyproject_dict
The optimization caches all Pydantic field accesses (`self.language`, `self.module_root`, etc.) into local variables at function start, eliminating repeated descriptor lookups that the profiler showed consuming 5–9% of runtime per conditional. Pydantic fields involve internal validation/descriptor machinery on each access, so reading `self.formatter_cmds` twice in the original `if formatter_cmds and formatter_cmds != ["black $file"]` line triggers two full lookups; the optimized version reads once into a local, then references that variable. The formatter check was also refactored to test list length before element comparison, avoiding unnecessary equality checks. Runtime improved 11% with no behavioral changes across 50+ test cases.1 parent 094d899 commit a8119b9
1 file changed
Lines changed: 33 additions & 19 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
55 | 55 | | |
56 | 56 | | |
57 | 57 | | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
58 | 71 | | |
59 | 72 | | |
60 | 73 | | |
61 | | - | |
62 | | - | |
| 74 | + | |
| 75 | + | |
63 | 76 | | |
64 | 77 | | |
65 | | - | |
66 | | - | |
67 | | - | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
68 | 81 | | |
69 | 82 | | |
70 | | - | |
71 | | - | |
| 83 | + | |
| 84 | + | |
72 | 85 | | |
73 | | - | |
74 | | - | |
75 | | - | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
76 | 90 | | |
77 | 91 | | |
78 | | - | |
79 | | - | |
| 92 | + | |
| 93 | + | |
80 | 94 | | |
81 | | - | |
82 | | - | |
| 95 | + | |
| 96 | + | |
83 | 97 | | |
84 | | - | |
| 98 | + | |
85 | 99 | | |
86 | 100 | | |
87 | | - | |
88 | | - | |
| 101 | + | |
| 102 | + | |
89 | 103 | | |
90 | | - | |
| 104 | + | |
91 | 105 | | |
92 | 106 | | |
93 | | - | |
| 107 | + | |
94 | 108 | | |
95 | 109 | | |
96 | 110 | | |
| |||
0 commit comments