json: make "memo" dict local to scan_once call #111928
Labels
3.13
bugs and security fixes
extension-modules
C modules in the Modules dir
topic-free-threading
type-feature
A feature request or enhancement
Feature or enhancement
The
Modules/_json.c
parser is mostly stateless (or the state is immutable). The one exception is the "memo" dictionary, which is used to avoid duplicatePyUnicodeObject
instances for the same JSON C strings.cpython/Modules/_json.c
Lines 696 to 700 in 289af86
The
memo
dictionary is already cleared after each callscan_once
:cpython/Modules/_json.c
Line 1118 in 289af86
We should move the creation and destruction of the
memo
dict to the invocation ofscan_once
instead of having it as part of the module state. This will avoid contention on the dictionary locks in--disable-gil
builds if multiple threads are concurrently parsing JSON strings.For an example modification, see colesbury/nogil-3.12@964bb33962.
Linked PRs
The text was updated successfully, but these errors were encountered: