From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.devel Subject: Re: Minor optimization in json.c Date: Sat, 13 Oct 2018 10:25:22 +0300 Message-ID: <83va66ux3x.fsf@gnu.org> References: <83efdld3no.fsf@gnu.org> <83zhw8bn1d.fsf@gnu.org> <83worcbbxj.fsf@gnu.org> NNTP-Posting-Host: blaine.gmane.org X-Trace: blaine.gmane.org 1539415443 8435 195.159.176.226 (13 Oct 2018 07:24:03 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sat, 13 Oct 2018 07:24:03 +0000 (UTC) Cc: emacs-devel@gnu.org To: Philipp Stephani Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sat Oct 13 09:23:59 2018 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gBEHH-00025a-1W for ged-emacs-devel@m.gmane.org; Sat, 13 Oct 2018 09:23:59 +0200 Original-Received: from localhost ([::1]:44029 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gBEJN-0004Nx-Gb for ged-emacs-devel@m.gmane.org; Sat, 13 Oct 2018 03:26:09 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:36491) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gBEIh-0004NP-Sf for emacs-devel@gnu.org; Sat, 13 Oct 2018 03:25:28 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gBEIe-00024s-MY for emacs-devel@gnu.org; Sat, 13 Oct 2018 03:25:27 -0400 Original-Received: from fencepost.gnu.org ([2001:4830:134:3::e]:54649) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gBEIc-00024G-Tv; Sat, 13 Oct 2018 03:25:24 -0400 Original-Received: from [176.228.60.248] (port=4067 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1gBEIX-0003Bw-Sn; Sat, 13 Oct 2018 03:25:20 -0400 In-reply-to: (message from Philipp Stephani on Wed, 3 Oct 2018 21:57:24 +0200) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2001:4830:134:3::e X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 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.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:230363 Archived-At: > From: Philipp Stephani > Date: Wed, 3 Oct 2018 21:57:24 +0200 > Cc: emacs-devel@gnu.org > > Thanks, just 2 stylistic comments. Thanks for reviewing the code. > 1. Could you try to eliminate global mutable state (i.e. the json_inserted_bytes global variable)? I know that > with the current threading implementation access is properly synchronized, but the global variable is still a > code smell and unnecessarily couples details of the threading implementation with the JSON adapter code. I > think you should be able to move it into the json_insert_data or json_buffer_and_size structures. I did that, but it needed adding new members to 2 data structures, and copying the values back and forth between them. Not sure this is more elegant. > 2. Could you try factoring out the buffer management code into new functions in insdel.c with a simple > interface? The details on how to keep track of the buffer insertion status aren't really related to JSON, and it > would be better to keep json.c focused on providing the JSON adapter (single responsibility principle). Maybe > with an interface such as: > void begin_insert_utf8_string (void); > void insert_utf8_string (const char *chars, ptrdiff_t nbytes); > void finish_insert_utf8_string (ptrdiff_t nbytes); I didn't do this. I don't like breaking code into functions that have no meaning on their own, especially when there's only one caller. (We do something similar in insert-file-contents, but the structure of the code and the details are sufficiently different that I decided not to make a single implementation that would support both.) I also don't agree with the argument about tracking the insertion status not being related to JSON: we do similar stuff in many places, and even json.c itself has similarly "unrelated" code, like the one under CONSP (lisp) in lisp_to_json_toplevel_1. The changes are now pushed to master.