Quantcast

JSON encoding and decoding performance

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

JSON encoding and decoding performance

Clément Pit--Claudel-4
Hi emacs-devel,

I'm running into performance issues with JSON encoding and decoding.  I have a language mode whose eldoc function makes a call to a language server running as a subprocess, and small lags tend to be visible when moving quickly around the buffer.  Profiling suggests that roughly 25 percent of the time is spent encoding and decoding JSON strings.

Would there be strong objections to supporting a C JSON library in addition to the current ELisp implementation?  This was suggested at one point in https://lists.gnu.org/archive/html/bug-gnu-emacs/2015-03/msg00770.html .  It would be similar in spirit to supporting libxml-parse-region along xml-parse-region, and it could provide nice speed boosts to json-heavy ELisp programs.

Cheers,
Clément.


smime.p7s (2K) Download Attachment
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: JSON encoding and decoding performance

Eli Zaretskii
> From: Clément Pit--Claudel <[hidden email]>
> Date: Sat, 15 Apr 2017 01:35:45 -0400
>
> I'm running into performance issues with JSON encoding and decoding.  I have a language mode whose eldoc function makes a call to a language server running as a subprocess, and small lags tend to be visible when moving quickly around the buffer.  Profiling suggests that roughly 25 percent of the time is spent encoding and decoding JSON strings.

Can you show the profiles?  IME, the devil is almost always in the
details.

> Would there be strong objections to supporting a C JSON library in addition to the current ELisp implementation?  This was suggested at one point in https://lists.gnu.org/archive/html/bug-gnu-emacs/2015-03/msg00770.html .  It would be similar in spirit to supporting libxml-parse-region along xml-parse-region, and it could provide nice speed boosts to json-heavy ELisp programs.

Since we have modules now, something that wasn't available back then,
you could roll your own library, right?

Anyway, I think more details about the bottlenecks would be necessary
to make the decision on what would be the best course of action.

Thanks.

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: JSON encoding and decoding performance

Clément Pit--Claudel-4
On 2017-04-15 03:59, Eli Zaretskii wrote:

>> From: Clément Pit--Claudel <[hidden email]> Date: Sat, 15 Apr 2017
>> 01:35:45 -0400
>>
>> I'm running into performance issues with JSON encoding and
>> decoding.  I have a language mode whose eldoc function makes a call
>> to a language server running as a subprocess, and small lags tend
>> to be visible when moving quickly around the buffer.  Profiling
>> suggests that roughly 25 percent of the time is spent encoding and
>> decoding JSON strings.
>
> Can you show the profiles?  IME, the devil is almost always in the
> details.
Sure; I've attached one.

>> Would there be strong objections to supporting a C JSON library in
>> addition to the current ELisp implementation?  This was suggested
>> at one point in
>> https://lists.gnu.org/archive/html/bug-gnu-emacs/2015-03/msg00770.html
>> .  It would be similar in spirit to supporting libxml-parse-region
>> along xml-parse-region, and it could provide nice speed boosts to
>> json-heavy ELisp programs.
>
> Since we have modules now, something that wasn't available back
> then, you could roll your own library, right?
That's right! I forgot about these. Let me try :)


slow-json (47K) Download Attachment
smime.p7s (2K) Download Attachment
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: JSON encoding and decoding performance

Mark Oteiza

Clément Pit--Claudel <[hidden email]> writes:

>>> Would there be strong objections to supporting a C JSON library in
>>> addition to the current ELisp implementation?  This was suggested
>>> at one point in
>>> https://lists.gnu.org/archive/html/bug-gnu-emacs/2015-03/msg00770.html
>>> .  It would be similar in spirit to supporting libxml-parse-region
>>> along xml-parse-region, and it could provide nice speed boosts to
>>> json-heavy ELisp programs.
>>
>> Since we have modules now, something that wasn't available back
>> then, you could roll your own library, right?
>
> That's right! I forgot about these. Let me try :)

Here's one: https://github.com/syohex/emacs-parson

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: JSON encoding and decoding performance

Eli Zaretskii
In reply to this post by Clément Pit--Claudel-4
> Cc: [hidden email]
> From: Clément Pit--Claudel <[hidden email]>
> Date: Sun, 16 Apr 2017 11:43:13 -0400
>
> > Can you show the profiles?  IME, the devil is almost always in the
> > details.
>
> Sure; I've attached one.

Looks like json-encode-alist takes most of the time, so the problem
might be in that function, not in the encoding itself.

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: JSON encoding and decoding performance

Philipp Stephani
In reply to this post by Clément Pit--Claudel-4


Clément Pit--Claudel <[hidden email]> schrieb am Sa., 15. Apr. 2017 um 08:59 Uhr:
Hi emacs-devel,

I'm running into performance issues with JSON encoding and decoding.  I have a language mode whose eldoc function makes a call to a language server running as a subprocess, and small lags tend to be visible when moving quickly around the buffer.  Profiling suggests that roughly 25 percent of the time is spent encoding and decoding JSON strings.

Would there be strong objections to supporting a C JSON library in addition to the current ELisp implementation?  This was suggested at one point in https://lists.gnu.org/archive/html/bug-gnu-emacs/2015-03/msg00770.html .  It would be similar in spirit to supporting libxml-parse-region along xml-parse-region, and it could provide nice speed boosts to json-heavy ELisp programs.

I think that's a great idea. I've heard complaints that JSON encoding is too slow for low-latency applications (e.g. https://github.com/abingham/emacs-ycmd/issues/163). This has apparently improved a bit in recent Emacs versions, but given the importance of JSON I think it definitely makes sense to have the fastest implementation available, even if that means reimplementing it in C.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: JSON encoding and decoding performance

Philipp Stephani
In reply to this post by Mark Oteiza


Mark Oteiza <[hidden email]> schrieb am So., 16. Apr. 2017 um 19:06 Uhr:

Clément Pit--Claudel <[hidden email]> writes:
>>> Would there be strong objections to supporting a C JSON library in
>>> addition to the current ELisp implementation?  This was suggested
>>> at one point in
>>> https://lists.gnu.org/archive/html/bug-gnu-emacs/2015-03/msg00770.html
>>> .  It would be similar in spirit to supporting libxml-parse-region
>>> along xml-parse-region, and it could provide nice speed boosts to
>>> json-heavy ELisp programs.
>>
>> Since we have modules now, something that wasn't available back
>> then, you could roll your own library, right?
>
> That's right! I forgot about these. Let me try :)

Here's one: https://github.com/syohex/emacs-parson

Thanks. I think the performance gain measured for that is quite convincing.
Loading...