FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

GH-137821: Convert `_json` to use Argument Clinic by hnnynh · Pull Request #138869 · python/cpython · GitHub

/ cpython Public

GH-137821: Convert _json to use Argument Clinic - #138869

Closed
hnnynh wants to merge 3 commits into
python:mainfrom
hnnynh:gh-137821
Closed

GH-137821: Convert _json to use Argument Clinic#138869
hnnynh wants to merge 3 commits into
python:mainfrom
hnnynh:gh-137821

Conversation

hnnynh commented Sep 13, 2025

Copy link
Copy Markdown
Contributor

This comment was marked as resolved.

Copy link
Copy Markdown
Member

I will plan to follow up her PR during the core sprint.

Comment thread Modules/_json.c
}

static inline int
_encoder_iterate_mapping_lock_held(PyEncoderObject *s, PyUnicodeWriter *writer,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Hmm, Would you like to explain why you remove xxxx_lock_held functions?
It's implemented for thread-safy in free-threading.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I didn't delete it myself; it got deleted when I ran make clinic.
Is it wrong to modify the code and then run make clinic?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I didn't delete it myself; it got deleted when I ran make clinic.
Is it wrong to modify the code and then run make clinic?

You should run make clinic first and then fill the declaration :)
But in that case, I think you should revert some change.

Comment thread Modules/_json.c
}

static inline int
_encoder_iterate_fast_seq_lock_held(PyEncoderObject *s, PyUnicodeWriter *writer,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

ditto

Comment thread Modules/_json.c
}

static inline int
_encoder_iterate_dict_lock_held(PyEncoderObject *s, PyUnicodeWriter *writer,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

ditto

Comment thread Modules/_json.c

corona10 left a comment
edited
Loading

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

About benchmark, you have to install pyperf with your newly builded CPython

$> ./python.exe -m venv .venv
$> source .venv/bin/activate
$> pip install pyperf

And then write benchmark in this way (This is just example, I expect more possible data you can expect)

import pyperf
import _json


small_obj = '{"foo": "bar"}'

def bench_encode_basestring_ascii(s):
    return _json.encode_basestring_ascii(s)


runner = pyperf.Runner()
runner.bench_func("bench_encode_basestring_ascii_small", bench_encode_basestring_ascii, small_obj)

Finally you can run benchmark with following way.

$> python bench_json.py -o base.json (with main branch)
$>  python bench_json.py -o ac.json (with your working branch)
$>   pyperf compare_to base.json ac.json (will show your benchmark comparation)

hnnynh commented Sep 14, 2025

Copy link
Copy Markdown
Contributor Author

About benchmark, you have to install pyperf with your newly builded CPython
...

I received the following execution results.

Benchmark hidden because not significant (1)

Since the code logic hasn't changed, I think the benchmark results should be the same and the result below is correct. Is that right?

Copy link
Copy Markdown
Member

Since the code logic hasn't changed, I think the benchmark results should be the same and the result below is correct. Is that right?

We suspsect the possibiity of overhead that are generated by AC but it looks not. But you also need to to write benchmark code for scanstring and encode_basestring.
And also test large size input for encode_basestring_ascii too

Comment thread Modules/_json.c
);
/*[clinic input]
_json.scanstring
pystr: object

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

You can use string as pystr to preserve original parameter name in Python. Thought, it's a positional-only argument and it's less important.

Comment thread Modules/_json.c
"character in s after the quote that started the JSON string.\n"
"Unescapes all valid JSON string escape sequences and raises ValueError\n"
"on attempt to decode an invalid string. If strict is False then literal\n"
"control characters are allowed in the string.\n"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Wait.

This paragraph of docstring is entirely lost. I think you shouldn't alter docstrings, except for case where you need to split out "summary line", per PEP 257. Everything else should go to a separate pr.

Comment thread Modules/_json.c
if (PyCFunction_Check(s->encoder)) {
PyCFunction f = PyCFunction_GetFunction(s->encoder);
if (f == py_encode_basestring_ascii) {
if (f == _json_encode_basestring_ascii) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Again, you can rename generated function to keep old name:

/*[clinic input]
_json.encode_basestring_ascii as py_encode_basestring_ascii
...

Comment thread Modules/_json.c
Comment on lines +1848 to +1849
ident = NULL;
s_fast = PySequence_Fast(seq, "_iterencode_list needs a sequence");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Why is this? I think it should be reverted, just as _encoder_iterate_fast_seq_lock_held() removal below.

Copy link
Copy Markdown
Member

@skirpichev I am now mentoring her, so I will ping you once she is ready to get review :) It's not ready now.

hnnynh closed this Oct 30, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants


Back | FazBrowse Home | New Git URL