Skip to content

Commit 403e004

Browse files
⚡️ Speed up function get_cached_gh_event_data by 31% in PR #371 (chore/error-on-missing-key-in-fork)
Here’s a faster and more memory-efficient version of your program. **Optimization rationale:** - Avoids the extra `Path` object creation and `.open()` call—using `open(event_path)` is faster for a single use. - Reduces dependency usage by not involving `Path` unless file system path manipulation is needed. - Leaves error handling as originally absent, maintaining original logic. - Leaves `lru_cache` as is and all function/return types unchanged. **Summary of change:** Direct file open instead of through `Path`, removing unnecessary abstraction for a single read and reducing overhead. All logic and return values are identical.
1 parent 47969c6 commit 403e004

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

codeflash/code_utils/env_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,5 +107,5 @@ def get_cached_gh_event_data() -> dict[str, Any] | None:
107107
event_path = os.getenv("GITHUB_EVENT_PATH")
108108
if not event_path:
109109
return None
110-
with Path(event_path).open() as f:
110+
with open(event_path) as f: # Open file directly for efficiency
111111
return json.load(f) # type: ignore # noqa

0 commit comments

Comments
 (0)