Commit 900de50
authored
Optimize TestGenRequest.to_payload
The optimization hoists `platform.python_version()` out of the per-call loop by caching it at module import time as `_PLATFORM_PYTHON_VERSION`, eliminating a 500+ns system call on every invocation when the language is not Python. The original code imported `platform` and called `platform.python_version()` inside `to_payload`, incurring repeated overhead even though the value never changes within a process. Line profiler shows the `import platform` statement itself consumed 6.6% of runtime, and the conditional evaluation another 7%. The payload dict construction was also reordered to compute `python_version` upfront, reducing incremental dict updates. This yields a 20% speedup (1.97ms → 1.64ms) with no correctness trade-offs.1 parent 9022f9e commit 900de50
1 file changed
Lines changed: 10 additions & 10 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| 15 | + | |
15 | 16 | | |
16 | 17 | | |
17 | 18 | | |
18 | 19 | | |
| 20 | + | |
| 21 | + | |
19 | 22 | | |
20 | 23 | | |
21 | 24 | | |
| |||
190 | 193 | | |
191 | 194 | | |
192 | 195 | | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
193 | 201 | | |
194 | 202 | | |
195 | 203 | | |
| |||
204 | 212 | | |
205 | 213 | | |
206 | 214 | | |
| 215 | + | |
| 216 | + | |
207 | 217 | | |
208 | 218 | | |
209 | | - | |
210 | | - | |
211 | | - | |
212 | | - | |
213 | | - | |
214 | | - | |
215 | | - | |
216 | | - | |
217 | | - | |
218 | | - | |
219 | 219 | | |
220 | 220 | | |
221 | 221 | | |
| |||
0 commit comments