Re: Re: RFC json_validate() - status: Under Discussion
| From: | Dennis Snell | Date: | Sat, 27 Aug 2022 17:58:48 +0000 |
| Subject: | Re: Re: RFC json_validate() - status: Under Discussion | ||
| References: | 1 2 3 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-118531@lists.php.net to get a copy of this message | ||
> The results in your linked gist, look odd though. Is 'is_valid_json()'
> referring to 'json_validate()'? Did you use the most recent version of
> the PR? I expect 'json_validate()' to be not slower than json_decode(),
> because it does strictly less. Also the peak memory usage of 79M is
> identical for all tested variants, this should not be the case for
> json_decode().
>
The results in my gist are only comparing user-land implementations to
json_decode()
and so I didn't include the RFC's code. is_valid_json() refers to the
function of the same name in my linked gist in json.php, and that's why it's
slower.
The peak memory usage comes from loading the input JSON document into memory. The linked benchmark
generates a 75 MB document. The reason I listed memory usage was to show that the parsing/validation
met the requirement: no additional memory use than what is required to read in the string.
This is all less of an argument for one solution or another and more trying to make sure that when
we are discussing the merits against user-land implementations that we're able to do so with
actual data instead of hand-waving. That data is basically that it's possible to build this in
about two half-days of work; it can run at least within half the speed of
json_decode(), and it can do so without allocating memory for the JSON data.
Thanks for looking into the code!