[meta] Use `orjson` compatibility shim everywhere we can
Categories
(Firefox Build System :: Mach Core, enhancement, P2)
Tracking
(Not tracked)
People
(Reporter: ahochheiden, Unassigned, Mentored)
References
(Depends on 1 open bug, Blocks 1 open bug)
Details
(Keywords: leave-open, meta, Whiteboard: [lang=python], [help wanted], [mentored])
Bug 1970516 added the orjson compatibility shim used by taskgraph to mozfile.
orjson is considerably faster than the stdlib json, so let's use it everywhere we can in firefox. Here's a searchfox query that should find all instances of import json or from json. In most cases, we should be able to just replace that with from mozfile import json or from mozfile.json import <function> and it should just work. One caveat is that the interface for orjson is not identical to the stdlib json, it only supports ident=2 and the sort_keys arguments.
If orjson is not compatible with how json is being used then the stdlib json will have to stay (but in some cases a file may need both, in that case use from mozfile import json as mozfile_json and update the orjson compatible code accordingly).
Here's an example patch of what was done in taskgraph: https://phabricator.services.mozilla.com/D251628
Most changes should follow a very similar formula, but they must be tested.
Future contributors 👋
For using this meta bug, let's follow the same pattern as bug 1714690 did for the six removals. Pick a directory with files that need this change and leave a comment here indicating that you want to work on that. Then either make your own bug or we'll do it and assign it to you. It should be titled something like Use 'mozfile.json' throughout 'python/mozbuild'. All the changes that need to be done in python/mozbuild will then be done under that bug.
Others could be python/mozboot, python/mach, js/src, etc.
Feel free to reach out to me if you have any questions.
| Reporter | ||
Comment 1•8 months ago
|
||
I've created a few bugs to make it easier to get started.
Comment 2•17 days ago
|
||
[:ahochheiden] Is the difference in separators during json.dumps expected?
$ ./mach python
Python 3.12.10 (tags/v3.12.10:0cc8128, Apr 8 2025, 12:21:36) [MSC v.1943 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> value={"a": 4}
>>> from mozfile import json as mozfile_json
>>> import json
>>> json.dumps(value)
'{"a": 4}'
>>> mozfile_json.dumps(value)
'{"a":4}'
Notice the space after colon in case of builtin json.dumps.
It's been a while since I last worked on this so I'm not sure why I didn't notice it before.
| Reporter | ||
Comment 3•17 days ago
|
||
I don't think it matters. It looks like the orjson output is just optimized to remove the unnecessary whitespace.
Description
•