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
Copy file name to clipboardExpand all lines: .agents/tasks/2025/08/21-0939-codetype-interface
+3-1Lines changed: 3 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -35,4 +35,6 @@ According to the PyO3 documentation it is preferred to use `Bound<'_, T>` instea
35
35
36
36
Also please add usage examples to the design documentation
37
37
--- FOLLOW UP TASK ---
38
-
Implement the CodeObjectWrapper as designed. Update the Tracer trait as well as the callback_xxx functions accordingly. Write a comprehensive unit tests for CodeObjectWrapper.
38
+
Implement the CodeObjectWrapper as designed. Update the Tracer trait as well as the callback_xxx functions accordingly. Write a comprehensive unit tests for CodeObjectWrapper.
39
+
--- FOLLOW UP TASK ---
40
+
There is an issue in the current implementation. We don't use caching effectively, since we create a new CodeObjectWrapper at each callback_xxx call. We need a global cache, probably keyed by the code object id. Propose design changes and update the design documents. Don't implement the changes themselves before I approve them.
Once cached, subsequent callbacks referencing the same `CodeType` will reuse the
122
+
existing wrapper without recomputing any attributes.
102
123
103
124
## Performance Considerations
104
125
-`Py<PyCode>` allows cloning the wrapper without holding the GIL, enabling cheap event propagation.
105
126
- Methods bind the owned reference to `Bound<'py, PyCode>` on demand, following PyO3's `Bound`‑first guidance and avoiding accidental `Py` clones.
106
127
- Fields are loaded lazily and stored inside `OnceCell` containers to avoid repeated attribute lookups.
107
128
-`line_for_offset` memoizes the full line table the first time it is requested; subsequent calls perform an in‑memory binary search.
108
129
- Storing strings and small integers directly in the cache eliminates conversion cost on hot paths.
130
+
- A global `CodeObjectRegistry` ensures that wrapper construction and attribute
131
+
discovery happen at most once per `CodeType`.
109
132
110
133
## Open Questions
111
134
- Additional attributes such as `co_consts` or `co_varnames` may be required for richer debugging features; these can be added later as new `OnceCell` fields.
112
135
- Thread‑safety requirements may necessitate wrapping the cache in `UnsafeCell` or providing internal mutability strategies compatible with `Send`/`Sync`.
136
+
- The registry currently grows unbounded; strategies for eviction or weak
137
+
references may be needed for long‑running processes that compile many
0 commit comments