# [RFC] Switch from json extension to jsonc [Discussion]

- Thread: https://externals.io/message/68664
- Original archive: https://news-web.php.net/php.internals/68664
- Started by Remi Collet on 2013-08-29T05:54:43+00:00
- Messages: 10
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · RFCs at https://externals.io/rfc.md · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #68664 — Remi Collet — 2013-08-29T05:54:43+00:00

URL: https://externals.io/message/68664#68664

Subject: Switch from json extension which have a problematic (non-free)
license  to jsonc dropin free alternative.

RFC: https://wiki.php.net/rfc/free-json-parser



Remi.

---

## #68666 — Stas Malyshev — 2013-08-29T06:25:40+00:00

URL: https://externals.io/message/68664#68666 · In reply to: #68664

Hi!

> Subject: Switch from json extension which have a problematic (non-free)
> license  to jsonc dropin free alternative.
> 
> RFC: https://wiki.php.net/rfc/free-json-parser

From what I see in the benchmarks, while encoding is on par with current
implementation, decoding is more than 2x slower. This may be a problem,
especially for something like REST API that may have to decode decent
amount of JSON data. Can it be fixed?

Also, I see the sizes of the encode results is different from ext/json.
Why is that?

Also, "Partial implementation of big integers parsing" is a bit
worrying. If we want to have drop-in replacement, partial
implementations would lead to trouble. Can it be fixed?


-- 
Stanislav Malyshev, Software Architect
SugarCRM: http://www.sugarcrm.com/
(408)454-6900 ext. 227

---

## #68667 — Remi Collet — 2013-08-29T06:41:38+00:00

URL: https://externals.io/message/68664#68667 · In reply to: #68666

Le 29/08/2013 08:25, Stas Malyshev a écrit :
> Hi!
> 
> > […]
> 
> > […]
> implementation, decoding is more than 2x slower. This may be a problem,
> especially for something like REST API that may have to decode decent
> amount of JSON data. Can it be fixed?

From my analysis (profiling), most of the time is spent in memory
allocation calls.

As we used a parser from a library, we do
1- parse in library space
2- object tree allocation of the result
3- copy result from library space to php space
4- PHP object tree allocation

I don't see any good solution to optimize this except copying the code
from the library into PHP, and thus remove stop 2+3.

> 
> Also, I see the sizes of the encode results is different from ext/json.
> Why is that?
> 
> Also, "Partial implementation of big integers parsing" is a bit
> worrying. If we want to have drop-in replacement, partial
> implementations would lead to trouble. Can it be fixed?

As the parsing is done in the library, we receive a int64. So to late.
As previously copying the code will allow such change.

Of course I have tried to avoid this (copying the code) and prefer to
keep the library unchanged... but...


Remi.

---

## #68668 — Remi Collet — 2013-08-29T06:55:07+00:00

URL: https://externals.io/message/68664#68668 · In reply to: #68666

Le 29/08/2013 08:25, Stas Malyshev a écrit :
> Also, I see the sizes of the encode results is different from ext/json.
> Why is that?

Stupid bench... data include some values from `microtime()`...
Fixed.

---

## #68669 — Remi Collet — 2013-08-29T07:31:20+00:00

URL: https://externals.io/message/68664#68669

Le 29/08/2013 09:04, Stas Malyshev a écrit :
> Hi!
> 
> > […]
> 
> Can't we just patch the lib to do the right thing? Is it just malloc vs.
> emalloc or deeper problems?

Probably deeper problem.
Moving to statically allocated stack (just a stupid test, of course) of
json_object only reduce time by ~15%...

> 
> > […]
> 
> > […]
> 
> Well, 2x slowdown is pretty serious. I didn't have a good look at the
> code so I can't advise how to fix it, but I think it needs to be fixed
> one way or another.

---

## #68670 — Zeev Suraski — 2013-08-29T07:52:43+00:00

URL: https://externals.io/message/68664#68670 · In reply to: #68664

I have to say that I'm not wildly enthusiastic about making this change over
what appears to be a fairly minor comment in the license, and without even
going into the discussion as to why we want to promote Evil :)

The main concerns I have are:
* Downwards compatibility.  We've found one potential issue, how can we
guarantee that there aren't others when we deal with a completely different
implementation?  I think that users that bump into apps suddenly breaking in
obscure edge cases will not be very understanding when we explain to them
that we did that over a licensing quirk - that I'm willing to bet they'll
say isn't applicable to them...
* Performance.  Again, for the same reasons, I think it'll be difficult for
us to defend this decision in this context as well.  We switched to a 2x
slower implementation over this?  Really?

I think that a better alternative would be enabling ext/jsonc to take over
the ext/json symbol space so that people who care about the license issue,
and/or are interested in the extra features - will be able to take advantage
of it as a drop-in replacement.  Debian can come with this switch turned on.

My 2c.

Zeev

> -----Original Message-----
> From: Remi Collet [mailto:remi@fedoraproject.org]
> Sent: Thursday, August 29, 2013 8:55 AM
> To: PHP Internals
> Subject: [PHP-DEV] [RFC] Switch from json extension to jsonc [Discussion]
>
> Subject: Switch from json extension which have a problematic (non-free)
> license  to jsonc dropin free alternative.
>
> RFC: https://wiki.php.net/rfc/free-json-parser
>
>
>
> Remi.
>
> --
>  To unsubscribe,
> visit:
> http://www.php.net/unsub.php

---

## #68708 — Jordi Boggiano — 2013-08-30T08:56:25+00:00

URL: https://externals.io/message/68664#68708 · In reply to: #68670

> I have to say that I'm not wildly enthusiastic about making this change over
> what appears to be a fairly minor comment in the license, and without even
> going into the discussion as to why we want to promote Evil :)
> 
> The main concerns I have are:
> * Downwards compatibility.  We've found one potential issue, how can we
> guarantee that there aren't others when we deal with a completely different
> implementation?  I think that users that bump into apps suddenly breaking in
> obscure edge cases will not be very understanding when we explain to them
> that we did that over a licensing quirk - that I'm willing to bet they'll
> say isn't applicable to them...
> * Performance.  Again, for the same reasons, I think it'll be difficult for
> us to defend this decision in this context as well.  We switched to a 2x
> slower implementation over this?  Really?
> 
> I think that a better alternative would be enabling ext/jsonc to take over
> the ext/json symbol space so that people who care about the license issue,
> and/or are interested in the extra features - will be able to take advantage
> of it as a drop-in replacement.  Debian can come with this switch turned on.

I think it'd be best to resolve this in PHP because otherwise it means
Debian (& Fedora?) users will have the bad surprise of a quirky
implementation when deploying to prod, and I can imagine the
impossible-to-reproduce issues that will follow.

That said, your last proposal of at least having a switch in php like
--enable-evil-json sounds better than the current state. If we do have
an equivalent implementation though we might as well throw away the
existing one instead of keeping two IMO, but that's a detail.

Cheers

-- 
Jordi Boggiano
@seldaek - http://nelm.io/jordi

---

## #68709 — Julien Pauli — 2013-08-30T09:07:02+00:00

URL: https://externals.io/message/68664#68709 · In reply to: #68708

> 
> > […]
> over
> > […]
> even
> > […]
> different
> > […]
> breaking in
> > […]
> for
> > […]
> over
> > […]
> issue,
> > […]
> advantage
> > […]
> on.
>
> I think it'd be best to resolve this in PHP because otherwise it means
> Debian (& Fedora?) users will have the bad surprise of a quirky
> implementation when deploying to prod, and I can imagine the
> impossible-to-reproduce issues that will follow.
>

I would say, to stay in the pipe, that then it would be a Debian issue, not
a PHP one.


>
> That said, your last proposal of at least having a switch in php like
> --enable-evil-json sounds better than the current state. If we do have
> an equivalent implementation though we might as well throw away the
> existing one instead of keeping two IMO, but that's a detail.
>

Seems good.

Julien.Pauli

---

## #68710 — Remi Collet — 2013-08-30T09:40:47+00:00

URL: https://externals.io/message/68664#68710 · In reply to: #68708

Le 30/08/2013 10:56, Jordi Boggiano a écrit :

> I think it'd be best to resolve this in PHP because otherwise it means
> Debian (& Fedora?) users will have the bad surprise of a quirky

Debian, Fedora, Mageia, Mandriva, Ubuntu, etc.

> implementation when deploying to prod, and I can imagine the
> impossible-to-reproduce issues that will follow.

This is clearly a important part of the proposal.
Having the same json implementation in "all" PHP.

Remi.

---

## #68723 — Levi Morrison — 2013-08-30T14:42:10+00:00

URL: https://externals.io/message/68664#68723 · In reply to: #68710

I definitely do not want a NON_STRICT mode for interpreting JSON. A
NON_STRICT mode is a very bad idea, no matter how well intentioned.
