You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
⚡️ Speed up function is_repo_a_fork by 40% in PR #371 (chore/error-on-missing-key-in-fork)
Here’s a **faster** version, making these improvements.
- Avoid repeatedly calling `os.getenv()` and `Path.open()` for the same event file, by using an explicit cache variable for the file contents. This accelerates repeated lookups and reduces disk accesses.
- Remove double @lru_cache use, as the value from `get_cached_gh_event_data()` will not change for a process lifetime and can be memory-cached explicitly.
- Microoptimize the `is_repo_a_fork` logic by removing an unnecessary bool(...) coercion (the value is already True/False).
Here’s the rewritten program.
**Key notes:**
- The event file is read at most once per process.
- All redundant calls and mutable global state are avoided.
- Fast subsequent access due to a module-level cache; you’ll see lower file-system and JSON load latency.
- The returned values are identical for the same environment and state, and function signatures are maintained.
Let me know if you want further micro-optimizations!
0 commit comments