Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rNWkB-00CydP-Fi for pgsql-hackers@arkaria.postgresql.org; Wed, 10 Jan 2024 11:27:36 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1rNWk8-002oTq-QC for pgsql-hackers@arkaria.postgresql.org; Wed, 10 Jan 2024 11:27:32 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rNWk8-002oTh-Cp for pgsql-hackers@lists.postgresql.org; Wed, 10 Jan 2024 11:27:32 +0000 Received: from mail-qk1-x72f.google.com ([2607:f8b0:4864:20::72f]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1rNWk4-000ow8-Vc for pgsql-hackers@lists.postgresql.org; Wed, 10 Jan 2024 11:27:31 +0000 Received: by mail-qk1-x72f.google.com with SMTP id af79cd13be357-783182d4a09so407901585a.2 for ; Wed, 10 Jan 2024 03:27:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dunslane-net.20230601.gappssmtp.com; s=20230601; t=1704886047; x=1705490847; darn=lists.postgresql.org; h=content-transfer-encoding:in-reply-to:subject:from:references:cc:to :content-language:user-agent:mime-version:date:message-id:from:to:cc :subject:date:message-id:reply-to; bh=RmTWL39oUOWOc1VQ/DG6bBD+TqJ9OYo4z/Aq/JxmPEQ=; b=aowEIflXNY50vI8FaOlRdSAXa0f0oIBd6jsCc4KhBXQz+gY7ek+936s2IUWIPX8x1x s94do7S5O8GMa1vCxCnQk3TKRhxZx1956DPCBiGPXeATqqMeR0sbu8P/g9aNNDwlI2tJ ULkEZ5Lqwr/Rf87rbv+B95He40n3Uhufte4LcJfFCbishJtb83J/sbClf4D1IopThkCW VBOy0FWEAxTA1ztRuBvcPGYa2l2n74Z9pO3/LxBXlXGXhYyHAbN1GkpcCVDIaf93OF3N aDU4IoD0Xp9bj4f6NJiLfz41e/cHVSMIahUClP6xRC9+KHE/vLJOKxX0I59MB0q/32fr R43w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704886047; x=1705490847; h=content-transfer-encoding:in-reply-to:subject:from:references:cc:to :content-language:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=RmTWL39oUOWOc1VQ/DG6bBD+TqJ9OYo4z/Aq/JxmPEQ=; b=W4/eVIfa9vAWWT07BWkrI4xMGAmzSJakVLS8PYLw+yomWC7qXReQKCppEaLdOGxO+t Qzx4OYnQlyJKWc5PkkC9Xll83MPQ1fvqyv20I+FphwOaJINTZoGzW9nfVTeWwOMlUg7J bKpxlpoxwSOdjLkb1fh6g71lj0k3eDCh4l+gA2EcMWVi13/wpkWFVcKkGhxNQ8s1IVrK HwmU8remR/PDHg6On9apQ8AlpQpkk4WNfSY1VVCbefORnC56m2ggkTvTW+JeqCAo/FKk NVTc1DOYgsdanWn2TkAsN9htd0LMFrmXm+lhUm+OSLfdX6lbirxTA+tSEoE1SwthMr5A eQSw== X-Gm-Message-State: AOJu0YxaaJ4Q2IDgLF9FK275KRODiVkYwa+1MTaDwnUSt9w+9N77i06R xQCN1qJGncb/7IZRlQFHMEZPb6s8qNNbrlvis6UkcceAY2Y= X-Google-Smtp-Source: AGHT+IGWhYVD91focBtSOE7Xh17NLVbXhIrkU5hFfua2bTTBSHnoUg3v5Fb4gdhUr/tmiZkI0qL8HA== X-Received: by 2002:a05:620a:1237:b0:77e:fba4:3a2c with SMTP id v23-20020a05620a123700b0077efba43a2cmr928860qkj.130.1704886046791; Wed, 10 Jan 2024 03:27:26 -0800 (PST) Received: from ?IPV6:2605:a601:91f3:1900::2bb? ([2605:a601:91f3:1900::2bb]) by smtp.googlemail.com with ESMTPSA id b13-20020a05620a0f8d00b007832af55e3csm1520638qkn.103.2024.01.10.03.27.25 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 10 Jan 2024 03:27:26 -0800 (PST) Message-ID: <0f81a871-0a5c-fd5b-14f6-52a2e886472c@dunslane.net> Date: Wed, 10 Jan 2024 06:27:24 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.15.1 Content-Language: en-US To: Jacob Champion Cc: PostgreSQL Hackers References: <7b0a51d6-0d9d-7366-3a1a-f74397a02f55@dunslane.net> From: Andrew Dunstan Subject: Re: WIP Incremental JSON Parser In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 2024-01-09 Tu 13:46, Jacob Champion wrote: > On Tue, Dec 26, 2023 at 8:49 AM Andrew Dunstan wrote: >> Quite a long time ago Robert asked me about the possibility of an >> incremental JSON parser. I wrote one, and I've tweaked it a bit, but the >> performance is significantly worse that that of the current Recursive >> Descent parser. > The prediction stack is neat. It seems like the main loop is hit so > many thousands of times that micro-optimization would be necessary... > I attached a sample diff to get rid of the strlen calls during > push_prediction(), which speeds things up a bit (8-15%, depending on > optimization level) on my machines. Thanks for looking! I've been playing around with a similar idea, but yours might be better. > > Maybe it's possible to condense some of those productions down, and > reduce the loop count? E.g. does every "scalar" production need to go > three times through the loop/stack, or can the scalar semantic action > just peek at the next token prediction and do all the callback work at > once? Also a good suggestion. Will look and see. IIRC I had trouble with this bit. > >> + case JSON_SEM_SCALAR_CALL: >> + { >> + json_scalar_action sfunc = sem->scalar; >> + >> + if (sfunc != NULL) >> + (*sfunc) (sem->semstate, scalar_val, scalar_tok); >> + } > Is it safe to store state (scalar_val/scalar_tok) on the stack, or > does it disappear if the parser hits an incomplete token? Good point. In fact it might be responsible for the error I'm currently trying to get to the bottom of. cheers andrew -- Andrew Dunstan EDB: https://www.enterprisedb.com