Skip to content

Commit 8b49b4b

Browse files
FindHaometa-codesync[bot]
authored andcommitted
Extend _json_compat with load/dump and migrate CUTracer to orjson
Summary: Extend tritonparse's `_json_compat.py` compatibility layer with file-based `load(f)` and `dump(obj, f)` convenience wrappers, then migrate all 14 CUTracer production Python files from stdlib `json` to use `tritonparse._json_compat`. This gives CUTracer a free performance upgrade via orjson for JSON parsing and serialization (3-10x faster), while maintaining graceful degradation to stdlib json in environments where orjson is unavailable. Key changes: - `_json_compat.py`: Add `load()` and `dump()` functions that delegate to the existing `loads()`/`dumps()` with file I/O wrapping - CUTracer: Replace `import json` with `from tritonparse._json_compat import ...` across query/, analyze/, reduce/, and validation/ modules - No changes to test files (consistent with tritonparse convention) - No changes to `scripts/parse_instr_hist_trace.py` (standalone, no tritonparse dep) CUTracer already depends on tritonparse (Buck + pip), so no new dependencies needed. ___ overriding_review_checks_triggers_an_audit_and_retroactive_review Oncall Short Name: triton Differential Revision: D99939361 fbshipit-source-id: 1ad5f9bce150e0aba8d7f55406e217d52cb923d2
1 parent fa507b3 commit 8b49b4b

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

tritonparse/_json_compat.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
1010
``loads()`` accepts ``str | bytes | bytearray | memoryview`` inputs.
1111
``dumps()`` returns ``str``.
12+
``load()`` and ``dump()`` provide file-like object I/O convenience wrappers.
1213
"""
1314

1415
try:
@@ -85,3 +86,20 @@ def dumps(obj, *, indent=False, sort_keys=False):
8586
if sort_keys:
8687
kwargs["sort_keys"] = True
8788
return _json.dumps(obj, **kwargs)
89+
90+
91+
def load(f):
92+
"""Deserialize a file-like object containing JSON to a Python object."""
93+
return loads(f.read())
94+
95+
96+
def dump(obj, f, *, indent=False, sort_keys=False):
97+
"""Serialize a Python object as JSON to a file-like object.
98+
99+
Args:
100+
obj: The object to serialize.
101+
f: A file-like object with a ``write()`` method.
102+
indent: If True, pretty-print with 2-space indent.
103+
sort_keys: If True, sort dictionary keys.
104+
"""
105+
f.write(dumps(obj, indent=indent, sort_keys=sort_keys))

0 commit comments

Comments
 (0)