Subject: Re: bug#20154: 25.0.50; json-encode-string is too slow for large strings

From: Dmitry Gutov <[email-masked]>
Date: Sun, 22 Mar 2015 21:03:19 +0200

On 03/22/2015 08:32 PM, Eli Zaretskii wrote:

> You said you need to encode everything on every keystroke, so I was

That was a simplification: "every keystroke" is an approximate 
description of frequency. But anyway, not every keystroke inserts a 
character. Some delete them, some invoke various commands, which may do 
complex things to buffer contents.

> wondering why you couldn't encode just the new keystroke, and append
> the result to what you already encoded earlier.
 > Then send everything
> to the server, as it expects.  The problem is in encoding, not in
> sending.

The server expects a certain JSON-encoded structure. You can't just 
append stuff at the end, that wouldn't be valid JSON.

I suppose you could first encode a "skeleton" alist, with some tagged 
values replacing the values that you'd expect to be big strings, and 
then substitute the values in before sending.

I'm sure you can imagine the (admittedly rare) edge cases when this will 
break, and it imposes new constraints on the organization of the code: 
where you could before just pass Emacs structures between functions to 
be encoded at the end just before sending, now you have to worry about 
the stuff above.