From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: =?utf-8?Q?Mattias_Engdeg=C3=A5rd?= Newsgroups: gmane.emacs.devel Subject: Re: I created a faster JSON parser Date: Tue, 12 Mar 2024 14:11:58 +0100 Message-ID: References: <87a5n96mb5.fsf@gmail.com> <20240309203725.x456m7c6soxtgj6q@nullprogram.com> <86jzmawqbm.fsf@gnu.org> <87ttldydf2.fsf@posteo.net> <867ci8vqvl.fsf@gnu.org> <5396AC95-1D8F-4A89-B4A8-647B717A1E3C@gmail.com> <87r0ggdcki.fsf@gmail.com> <437D901F-CEC6-45E0-8ABE-B036A7B0AAF5@gmail.com> <87jzm7itw8.fsf@gmail.com> Mime-Version: 1.0 (Mac OS X Mail 14.0 \(3654.120.0.1.15\)) Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="31747"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Eli Zaretskii , Philip Kaludercic , wellons@nullprogram.com, emacs-devel , =?utf-8?Q?Gerd_M=C3=B6llmann?= To: =?utf-8?B?Ikhlcm1hbiwgR8OpemEi?= Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Tue Mar 12 14:13:12 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 1rk1wN-00087K-0q for ged-emacs-devel@m.gmane-mx.org; Tue, 12 Mar 2024 14:13:11 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rk1vf-00064A-VF; Tue, 12 Mar 2024 09:12:28 -0400 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 1rk1vP-00061Q-PA for emacs-devel@gnu.org; Tue, 12 Mar 2024 09:12:13 -0400 Original-Received: from mail-lf1-x134.google.com ([2a00:1450:4864:20::134]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rk1vK-0006PV-CZ; Tue, 12 Mar 2024 09:12:11 -0400 Original-Received: by mail-lf1-x134.google.com with SMTP id 2adb3069b0e04-5135e8262e4so5921024e87.0; Tue, 12 Mar 2024 06:12:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1710249121; x=1710853921; darn=gnu.org; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:sender:from:to:cc:subject :date:message-id:reply-to; bh=Wjwuvz4V7oaP5FORSZ00zSEB/vsk1X6nV46TUX/HmGA=; b=FPcbFLX7hLUpOyoWZ0K/ViSCnUNG2cEIfQB9g8ERLPhifvF/pPdfDtRo1MYWveTHao thOK2AzVms4OruBn4UV9e4mkAh0JmBX3sQRUagIT8FqYsfiJ7TTgyM/OjM/zBceoYE3q d010NZmEJmkAIW9sj1MUR8U1p3XfIFS9sEv2Ksh0LkKjxECwSVsObrYOik+RPBYaOBpK fixJY15bq8BQoTIU8C401IjDFl+BcOaFGcTa/faURb8p4tgw2Mm0r1yA45ZbPglQna9/ 2iHo2jc4kFmMAswalmtbKPegW0gkoVbz/GQHnwDOrHcVC2om+jfOxI15ziKorgda3jzK 0UWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710249121; x=1710853921; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:sender:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=Wjwuvz4V7oaP5FORSZ00zSEB/vsk1X6nV46TUX/HmGA=; b=BXhcAts6RupOECGiLsoH2A7lkIyxdPZM1lrBwK0ZEVNghHEideuWD9QF8cMEsdJ9Ut pydwbgFYsDNW0+6Qb+sRDqp++eYJq1ZvkhvimoU3wGM8/XGAB7DdoGAiPRryBJtsimPx hYiYKBh1AoQZJKDOUZzaVMtU6TJsWBv+HluUmRUr28KbRiCaP1+pl0gOV9pScVA3/jA2 LyapL+Cctl6e41V7/tTX4QCXfeohSg1j/o/yGurP1U1cv+qa3uHjPCEB64CoaCJHz8Oj zpfx4yjRcnJak13V07ed8T/WLvfY0JE/jFEN0OKEK94+uJwNykTJOxLh9G8AlcbAPr+u qEsQ== X-Forwarded-Encrypted: i=1; AJvYcCX8jmx02mRnJ2eP6fpvbMVGlA0yg8o2S2fXgsPefe2Jccq+XSFajkJQm9Ev1DZ9U35Tz7F+aSSjPN/bvt5ujSV/DXyx X-Gm-Message-State: AOJu0YzgZddbOIz1hwX8D6HNFZmnm4G8E+8IymedVbMFLwMmvF8TUzaQ P27XKuiZIcjAVv0Vxvi+eo2VLxH2RomXTall7EQjYIKDm6yaXbwP X-Google-Smtp-Source: AGHT+IF/YFv59Zzs27AJuei/ZWFvbZeVZZDDISfXjHYuxEdgev2n7ad4Xb/LaMvFuLfwOOr0EbHsMw== X-Received: by 2002:ac2:57c1:0:b0:513:a741:bbe1 with SMTP id k1-20020ac257c1000000b00513a741bbe1mr4007326lfo.31.1710249121289; Tue, 12 Mar 2024 06:12:01 -0700 (PDT) Original-Received: from smtpclient.apple (c80-217-1-132.bredband.tele2.se. [80.217.1.132]) by smtp.gmail.com with ESMTPSA id d13-20020a05651233cd00b005134a7b5369sm1573789lfg.4.2024.03.12.06.12.00 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 12 Mar 2024 06:12:00 -0700 (PDT) In-Reply-To: <87jzm7itw8.fsf@gmail.com> X-Mailer: Apple Mail (2.3654.120.0.1.15) Received-SPF: pass client-ip=2a00:1450:4864:20::134; envelope-from=mattias.engdegard@gmail.com; helo=mail-lf1-x134.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action 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:317016 Archived-At: 12 mars 2024 kl. 11.58 skrev Herman, G=C3=A9za : >> You can't test that code is GC-safe, you have to show that it's = correct by design. >=20 > Sure, but there has to be an explanation why the current way doesn't = have any problems. It doesn't matter -- we don't need to prove to you why you don't get a = segfault, it's you who need to convince us that your code is fine. Most C code does not need any special attention as long as it only = places Lisp roots in local variables, ie, on the C stack and in = registers. Your code keeps live roots in heap-allocated memory. It's not = alone in doing that, but elsewhere we give those roots special = attention, either by explicit GC marking or disabling GC during the = lifespan of those roots. As I said your code is probably safe unless it signals an error. An alternative is to do as Gerd suggested and only have roots on the = stack, by allocating vectors (or lists) for the task. However: 12 mars 2024 kl. 12.33 skrev Gerd M=C3=B6llmann = : > Will any user ever notice a difference? I doubt it. I can't say, and these things are not always easy to measure. A Lisp = allocation has the drawbacks: - Allocation requires initialisation of the entire block, not just the = used part. - Deallocation is delayed until the next GC. - The cache lines are effectively wasted. - If the code is run again before next GC, it will have to allocate more = Lisp objects. - GC happens more frequently because allocation advances the GC clock. - GC takes longer because it has to sweep more dead objects. One compromise in this case (json_parse_array) would be to collect array = elements into a Lisp list which is then turned into a Lisp vector. In = the latter case we could use free_cons to undo the consing if we want. Consing and list traversal is slow but perhaps not bad enough; = measurement is needed.