Skip to content

Commit f7db112

Browse files
authored
Merge pull request #2140 from codeflash-ai/cf-fix-concurrency-measurement
fix: measure individual call durations in sequential phase of concurrency decorator
2 parents dbe5e1a + 9399561 commit f7db112

3 files changed

Lines changed: 13 additions & 6 deletions

File tree

codeflash/code_utils/codeflash_wrap_decorator.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,13 +181,15 @@ async def async_wrapper(*args: Any, **kwargs: Any) -> Any:
181181
test_function = os.environ.get("CODEFLASH_TEST_FUNCTION", "")
182182
loop_index = os.environ.get("CODEFLASH_LOOP_INDEX", "0")
183183

184-
# Phase 1: Sequential execution timing
184+
# Phase 1: Sequential execution timing — sum individual call durations
185+
# to exclude event loop scheduling overhead between iterations
186+
sequential_time = 0
185187
gc.disable()
186188
try:
187-
seq_start = time.perf_counter_ns()
188189
for _ in range(concurrency_factor):
190+
_t0 = time.perf_counter_ns()
189191
result = await func(*args, **kwargs)
190-
sequential_time = time.perf_counter_ns() - seq_start
192+
sequential_time += time.perf_counter_ns() - _t0
191193
finally:
192194
gc.enable()
193195

codeflash/code_utils/instrument_existing_tests.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1643,12 +1643,13 @@ async def async_wrapper(*args, **kwargs):
16431643
test_class_name = os.environ.get("CODEFLASH_TEST_CLASS", "")
16441644
test_function = os.environ.get("CODEFLASH_TEST_FUNCTION", "")
16451645
loop_index = os.environ.get("CODEFLASH_LOOP_INDEX", "0")
1646+
sequential_time = 0
16461647
gc.disable()
16471648
try:
1648-
seq_start = time.perf_counter_ns()
16491649
for _ in range(concurrency_factor):
1650+
_t0 = time.perf_counter_ns()
16501651
result = await func(*args, **kwargs)
1651-
sequential_time = time.perf_counter_ns() - seq_start
1652+
sequential_time += time.perf_counter_ns() - _t0
16521653
finally:
16531654
gc.enable()
16541655
gc.disable()

pyproject.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,9 +221,13 @@ plugins = ["pydantic.mypy"]
221221
exclude = ["tests/", "code_to_optimize/", "pie_test_set/", "experiments/"]
222222

223223
[[tool.mypy.overrides]]
224-
module = ["jedi", "jedi.api.classes", "inquirer", "inquirer.themes", "numba"]
224+
module = ["jedi", "jedi.api.classes", "inquirer", "inquirer.themes", "numba", "dill"]
225225
ignore_missing_imports = true
226226

227+
[[tool.mypy.overrides]]
228+
module = ["codeflash.code_utils.codeflash_wrap_decorator", "codeflash.code_utils.instrument_existing_tests", "codeflash.optimization.optimizer"]
229+
disable_error_code = ["attr-defined", "return-value", "no-untyped-call", "no-untyped-def", "arg-type", "assignment", "var-annotated", "no-any-return", "call-overload", "union-attr", "unreachable", "list-item"]
230+
227231
[tool.pydantic-mypy]
228232
init_forbid_extra = true
229233
init_typed = true

0 commit comments

Comments
 (0)