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 1rrlRE-002aIj-6I for pgsql-hackers@arkaria.postgresql.org; Tue, 02 Apr 2024 21:13:00 +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 1rrlRC-00CBIG-F5 for pgsql-hackers@arkaria.postgresql.org; Tue, 02 Apr 2024 21:12:58 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rrlRB-00CBI8-Vb for pgsql-hackers@lists.postgresql.org; Tue, 02 Apr 2024 21:12:58 +0000 Received: from mail-oi1-x22e.google.com ([2607:f8b0:4864:20::22e]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1rrlR8-000FYL-BT for pgsql-hackers@lists.postgresql.org; Tue, 02 Apr 2024 21:12:56 +0000 Received: by mail-oi1-x22e.google.com with SMTP id 5614622812f47-3c4f23d23d9so772614b6e.3 for ; Tue, 02 Apr 2024 14:12:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dunslane-net.20230601.gappssmtp.com; s=20230601; t=1712092373; x=1712697173; 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=sIxpPLHK3SdiqaDFyHAxWyxZt06nUFcYHWX3G7TwdSw=; b=0C2fGO/6Ekt8c4Lozl+N1ipFiCtbD0/SPgx/ycOHIZiAqiFAjVqArAubI6xy/j877Y kzwY2w8WXQxbZJfxLyGbxBBvVCKFJ3q+EiSiIANLXIO/T58FV6rv4/3TP+PPKv4nl5J7 NEW7gGjCeaB654GCQD2rldlMSqCuwYOJaGq9YMwauADQI0UQAv0QMcPySlalM93wGM95 Nrkv4Wrseer7awoQWdHnV/rLBV2Vww+bX38qKYrW+iFCP3Yz4ORVlAjJRC62fOQpsPDe SKn10P9LiLNypi/uatBPdaVhsvHh8V6FwA37eoykp0KGj80X2niNydeSVZqkGCZ6JdKF iy4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712092373; x=1712697173; 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=sIxpPLHK3SdiqaDFyHAxWyxZt06nUFcYHWX3G7TwdSw=; b=dHBEg0DyF6ICotwaWI3J+cV0NURA2Up/CSuaLMevxBZCvo0I5/L+n/6vuT+9zbmh/A iuz9FXqS7jNZMi5wXeZDITC4OwZp7F8KlM815kDnJ8+zAljijWT2/8vcCVwXnpuzVoRz R8nZTKAvHpU2mtFb6tYZIqb1cixqJueMh64tmyUFj4s/6v+ldyvC8JVPniNNfJA9fk1/ wv3v0lo8xRzoKJLEIuPC2s4yKMXPbnejLSMddMr07atm/RMObwuqrm+7qqemT1OSi1Yq jQRCKDasXBKNxI3sY+mIxGjDH7uLUE1MGQojh9dwjAQFxJQaIlcjSgzgg7smvxtzVhjC kLtA== X-Forwarded-Encrypted: i=1; AJvYcCW7trqf9aq+H1IlWshhpoJ4tAHBHXr4dfdHrXHwaeZrCVsT208s5k7P2MTwsEE3NpJRYAtgoRccGt/C0Q4HyiyUI0Kynh8DKwk7JGwOCexzqWXR X-Gm-Message-State: AOJu0Yw63xjfbpuTsBHry4B2ee1mbvFPRHIqJiaJUGSUulnG0fF/kc6K 4pAIytMzS488/pGt5wcflyydYZQJ617cEqPTd8w2L+oYagxC8/MkgG6D+PRFBt8= X-Google-Smtp-Source: AGHT+IHS1vxxRvaV0Ekpjl0bKi95vLROU+23EtNds2srA8TjCbJZ/EDLa0nSDNS86obvnzidFkU+uw== X-Received: by 2002:a05:6808:18a7:b0:3c4:ebc9:e7a3 with SMTP id bi39-20020a05680818a700b003c4ebc9e7a3mr7337736oib.5.1712092373169; Tue, 02 Apr 2024 14:12:53 -0700 (PDT) Received: from ?IPV6:2605:a601:9180:9800::2bb? ([2605:a601:9180:9800::2bb]) by smtp.googlemail.com with ESMTPSA id bi22-20020a05620a319600b0078bc77b2039sm3846116qkb.18.2024.04.02.14.12.52 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 02 Apr 2024 14:12:52 -0700 (PDT) Message-ID: <8447d168-b981-2601-8ad0-53827fe18e5a@dunslane.net> Date: Tue, 2 Apr 2024 17:12:51 -0400 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: Robert Haas , Peter Smith , PostgreSQL Hackers References: <7b0a51d6-0d9d-7366-3a1a-f74397a02f55@dunslane.net> <12e54bab-7b9e-c36e-5541-09e1603ae0a4@dunslane.net> <7ead3d4d-ddc6-2499-0a04-6b29c693ea4a@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-04-02 Tu 15:38, Jacob Champion wrote: > On Mon, Apr 1, 2024 at 4:53 PM Andrew Dunstan wrote: >> Anyway, here are new patches. I've rolled the new semantic test into the >> first patch. > Looks good! I've marked RfC. Thanks! I appreciate all the work you've done on this. I will give it one more pass and commit RSN. > >> json_lex() is not really a very hot piece of code. > Sure, but I figure if someone is trying to get the performance of the > incremental parser to match the recursive one, so we can eventually > replace it, it might get a little warmer. :) I don't think this is where the performance penalty lies. Rather, I suspect it's the stack operations in the non-recursive parser itself. The speed test doesn't involve any partial token processing at all, and yet the non-recursive parser is significantly slower in that test. >>> I think it'd be good for a v1.x of this feature to focus on >>> simplification of the code, and hopefully consolidate and/or eliminate >>> some of the duplicated parsing work so that the mental model isn't >>> quite so big. >> I'm not sure how you think that can be done. > I think we'd need to teach the lower levels of the lexer about > incremental parsing too, so that we don't have two separate sources of > truth about what ends a token. Bonus points if we could keep the parse > state across chunks to the extent that we didn't need to restart at > the beginning of the token every time. (Our current tools for this are > kind of poor, like the restartable state machine in PQconnectPoll. > While I'm dreaming, I'd like coroutines.) Now, whether the end result > would be more or less maintainable is left as an exercise... > I tried to disturb the main lexer processing as little as possible. We could possibly unify the two paths, but I have a strong suspicion that would result in a performance hit (the main part of the lexer doesn't copy any characters at all, it just keeps track of pointers into the input). And while the code might not undergo lots of change, the routine itself is quite performance critical. Anyway, I think that's all something for another day. cheers andrew -- Andrew Dunstan EDB: https://www.enterprisedb.com