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 1rL2ik-005nyf-MN for pgsql-hackers@arkaria.postgresql.org; Wed, 03 Jan 2024 14:59:50 +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 1rL2ig-005nwu-JD for pgsql-hackers@arkaria.postgresql.org; Wed, 03 Jan 2024 14:59:46 +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 1rL2ig-005nwj-5n for pgsql-hackers@lists.postgresql.org; Wed, 03 Jan 2024 14:59:46 +0000 Received: from mail-yb1-xb29.google.com ([2607:f8b0:4864:20::b29]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1rL2ib-00FLtL-1Y for pgsql-hackers@lists.postgresql.org; Wed, 03 Jan 2024 14:59:44 +0000 Received: by mail-yb1-xb29.google.com with SMTP id 3f1490d57ef6-dbe39a45e8eso3499553276.1 for ; Wed, 03 Jan 2024 06:59:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dunslane-net.20230601.gappssmtp.com; s=20230601; t=1704293979; x=1704898779; 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=xiIXM3QZUhbAYtZwa2nqAmHkW3aT488Wmb6ashb0ajs=; b=m22EZP/hLX6wctDpR+7T8YkpaopILj+S7gh/c/6/cPmHUb5XbTVnYcGD5i5/rfMJut 9V7mxD+F54fZIkZWDfr/OForwRMO1QSCd9DckH3S/IAhBqHS1dxb6xX4c2qyk5zder+T DOvgzpE3xr3zeVuLiinAXdX2Pd/dzhYqC5umOMCFnMwFNPVyfyIXqySrtE1OzrwkwINw /eLL8urbZhtg6fgAbvyDD+E4UABiwoTwgnZfT9sqYQVnoWH9FFeUMyyQnLM7hlHmItGK QIqApRKnU9Ml3inDUS+/21tlU8UV7Q0i7XiusZqvW2oaUcUXb8a30gZ46iEI6xg1+RaL s1kg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704293979; x=1704898779; 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=xiIXM3QZUhbAYtZwa2nqAmHkW3aT488Wmb6ashb0ajs=; b=IFPpE7vwAU3Cz+qNy6OkqXiy0EpWR1KNsbh07v9MQ6vBaPM5+jhh1QZlEHLJeyJAFk b4+/wq6ZVy7OIXkFiltWiqG2zflZr/aV4yRngrtzz0YTc2iERb/Gy3mlib2AJCWmGAju YQVUXHsvmuw8fFGNP2Z2r+dcWdkr5g7Ff2I5USNtMslQXgCaBCT9sMnb/Kn7/+UcCek8 O5Jo24e53A49wUS5RbNMiM8ma6jQmrVTpUkozcHkZipmIVmNvIerxFirk29b2M4ZUD3T OGTbGauDexozOQnVvl2s7/kzw55VeAdSHygOMVnAQTMRALWDXx0jL8U31JE0irci2YQb ZQlQ== X-Gm-Message-State: AOJu0YyincppmjCcnib5aw3IBbgQvw1aPI37i6x5ettGCLg6lr/DtFRn CsPj4rrNzAkAy//CDehbthfrqfrNbzU0lQ== X-Google-Smtp-Source: AGHT+IE6vRY8Zv7CP+T1yXn0PDMALmCs3kEVfB/8LHM8B9F0Xy/bKdQDIebTMsrZihTH+YGo/LpLxQ== X-Received: by 2002:a25:9:0:b0:dbd:5964:1ad6 with SMTP id 9-20020a250009000000b00dbd59641ad6mr8601656yba.125.1704293978796; Wed, 03 Jan 2024 06:59:38 -0800 (PST) Received: from ?IPV6:2605:a601:91f3:1900::2bb? ([2605:a601:91f3:1900::2bb]) by smtp.googlemail.com with ESMTPSA id d2-20020a0ce442000000b0067f81b6891csm10772309qvm.85.2024.01.03.06.59.38 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 03 Jan 2024 06:59:38 -0800 (PST) Message-ID: <58987a44-878a-338b-31de-4543c90604f1@dunslane.net> Date: Wed, 3 Jan 2024 09:59:37 -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: Robert Haas Cc: PostgreSQL Hackers References: <7b0a51d6-0d9d-7366-3a1a-f74397a02f55@dunslane.net> <253cef9e-1360-a1a6-5091-ad4368b1b8cc@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-03 We 08:45, Robert Haas wrote: > On Wed, Jan 3, 2024 at 6:57 AM Andrew Dunstan wrote: >> Yeah. One idea I had yesterday was to stash the field names, which in >> large JSON docs tent to be pretty repetitive, in a hash table instead of >> pstrduping each instance. The name would be valid until the end of the >> parse, and would only need to be duplicated by the callback function if >> it were needed beyond that. That's not the case currently with the >> parse_manifest code. I'll work on using a hash table. > IMHO, this is not a good direction. Anybody who is parsing JSON > probably wants to discard the duplicated labels and convert other > heavily duplicated strings to enum values or something. (e.g. if every > record has {"color":"red"} or {"color":"green"}). So the hash table > lookups will cost but won't really save anything more than just > freeing the memory not needed, but will probably be more expensive. I don't quite follow. Say we have a document with an array 1m objects, each with a field called "color". As it stands we'll allocate space for that field name 1m times. Using a hash table we'd allocated space for it once. And allocating the memory isn't free, although it might be cheaper than doing hash lookups. I guess we can benchmark it and see what the performance impact of using a hash table might be. Another possibility would be simply to have the callback free the field name after use. for the parse_manifest code that could be a one-line addition to the code at the bottom of json_object_manifest_field_start(). >> The parse_manifest code does seem to pfree the scalar values it no >> longer needs fairly well, so maybe we don't need to to anything there. > Hmm. This makes me wonder if you've measured how much actual leakage there is? No I haven't. I have simply theorized about how much memory we might consume if nothing were done by the callers to free the memory. cheers andrew -- Andrew Dunstan EDB: https://www.enterprisedb.com