From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.devel Subject: Re: I created a faster JSON parser Date: Fri, 08 Mar 2024 21:57:28 +0200 Message-ID: <86cys4zec7.fsf@gnu.org> References: <87a5n96mb5.fsf@gmail.com> <861q8l0w2c.fsf@gnu.org> <878r2s99j0.fsf@gmail.com> <86y1aszxom.fsf@gnu.org> <874jdg97xm.fsf@gmail.com> <86ttlgzuew.fsf@gnu.org> <875xxw3f3a.fsf@gmail.com> <86plw4zo9u.fsf@gnu.org> <87edcktumt.fsf@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="15251"; mail-complaints-to="usenet@ciao.gmane.io" Cc: emacs-devel@gnu.org To: =?utf-8?Q?Herman_G=C3=A9za?= Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Fri Mar 08 20:58:23 2024 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1rigMI-0003mK-V8 for ged-emacs-devel@m.gmane-mx.org; Fri, 08 Mar 2024 20:58:22 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rigLW-00075F-KA; Fri, 08 Mar 2024 14:57:34 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rigLU-000752-LJ for emacs-devel@gnu.org; Fri, 08 Mar 2024 14:57:32 -0500 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rigLU-0006pb-Cr; Fri, 08 Mar 2024 14:57:32 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-version:References:Subject:In-Reply-To:To:From: Date; bh=ysfE42Y9vPOrz65YDTCf/F5tz+5dzpCeTmYY6xVrJZI=; b=NFFvYM+fRon6lkLSQesL 2SaoYlU89pRx1fis3+ioIfARmb4VJzGt2VoTD3ETI3LXVrI68qCKsuI8Oqzmk2MB7uVcZ+UdS+FzV bDfu1RnrpbhjTWqQgq/06SzdTDJBRdC0KxZHOv7qEpvU5n2HMLiMvDP86zcVFr6Zf9Ea4jg1Q6HnN lRZFyWRmiJdy+ZqEfzb0cu7bRGpZSJxJnuZ9D0/AAh1554Jul5HEcMX1YaGOUclK6tT8rP1nvcZa5 +koxa468gfG4RGygM1ioYN4dFsN6mDBUqkZksA+JR+kGTXZ6rUBE/mfv3EmH0p+KE3I/QPDeE/CO0 IVOYuszBvKo5cw==; In-Reply-To: <87edcktumt.fsf@gmail.com> (message from Herman, =?utf-8?Q?G?= =?utf-8?Q?=C3=A9za?= on Fri, 08 Mar 2024 19:34:28 +0100) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:316927 Archived-At: > From: Herman, Géza > Cc: geza.herman@gmail.com, emacs-devel@gnu.org > Date: Fri, 08 Mar 2024 19:34:28 +0100 > > > If you want to use a 32-bit type, use 'int' or 'unsigned int'. > I want to use a datatype which is likely to have the same size as > a CPU register. On 32-bit machines, it should be 32-bit, on 64-bit > architectures it should be 64-bit. Is there a reason for you to want it to be 64-bit type on a 64-bit machine? If the only bother is efficiency, then you can use 'int' without fear. But if a 64-bit machine will need the range of values beyond INT_MAX (does it?), then I suggest to use ptrdiff_t. > This is not a strong requirement, but it makes the parser faster. Are you sure? AFAIK, 32-bit arithmetics on a 64-bit machine is as fast as 64-bit arithmetics. So if efficiency is the only consideration, using 'int' is OK. > During number parsing, this part of the code calculates the value of > the number. If it overflows, or it ends up being a float, then the > workspace buffer is re-parsed to find the value. But if it is an > integer without overflow, the parser just can use the value without > any further processing (a certain kind of LSP message is basically a > large array of integers, so it makes sense to optimize this case - > this optimization makes parsing such messages 1.5-2x faster). If the value needs to fit in a fixnum, use EMACS_INT, which is a type that already takes the 32-but vs 64-bit nature of the machine into consideration. > > We need to decide what to do with characters outside of the > > Unicode range. The encoding of those characters is different, > > btw, it doesn't follow the UTF-8 scheme. > > > > In any case, the error in those cases cannot be just "json parse > > error", it must be something more self-explanatory. > I am open to suggestions, as even after reading "Text > Representations" in the manual, I have no idea what to do here. We should begin by deciding whether we want to support characters outside of the Unicode range. The error message depends on that decision. > I didn't find any code which handles this case in the jansson parser > either. The jansson code required encoding/decoding strings to make sure we submit to jansson text that is always valid UTF-8.