Commit 7fbed29
authored
Here's an optimized version of your Python program, focused on runtime and memory.
**Key changes:**
- Avoids reading the event file or parsing JSON if not needed.
- Reads the file as binary and parses with `json.loads()` for slightly faster IO.
- References the `"draft"` property directly using `.get()` to avoid possible `KeyError`.
- Reduces scope of data loaded from JSON for less memory usage.
- Caches the result of parsing the event file for repeated calls within the same process.
- The inner try/except is kept close to only catching the specific case.
- Results for each event_path file are cached in memory.
- Exception handling and comments are preserved where their context is changed.
- I/O and JSON parsing is only done if both env vars are set and PR number exists.
1 parent eba8cb8 commit 7fbed29
1 file changed
+20
-10
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
125 | 125 | | |
126 | 126 | | |
127 | 127 | | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
128 | 142 | | |
129 | | - | |
130 | | - | |
131 | | - | |
132 | | - | |
133 | | - | |
134 | | - | |
135 | | - | |
136 | | - | |
137 | | - | |
138 | | - | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
0 commit comments