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 1rBO2B-00AetG-9J for pgsql-hackers@arkaria.postgresql.org; Thu, 07 Dec 2023 23:43:59 +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 1rBO29-002xLw-2h for pgsql-hackers@arkaria.postgresql.org; Thu, 07 Dec 2023 23:43:57 +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 1rBO28-002xLm-LL for pgsql-hackers@lists.postgresql.org; Thu, 07 Dec 2023 23:43:56 +0000 Received: from mail-pl1-x62d.google.com ([2607:f8b0:4864:20::62d]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1rBO22-009K6P-Ve for pgsql-hackers@postgresql.org; Thu, 07 Dec 2023 23:43:55 +0000 Received: by mail-pl1-x62d.google.com with SMTP id d9443c01a7336-1d048c171d6so13686055ad.1 for ; Thu, 07 Dec 2023 15:43:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=j-davis-com.20230601.gappssmtp.com; s=20230601; t=1701992629; x=1702597429; darn=postgresql.org; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:cc:to:from:subject:message-id:from:to:cc:subject :date:message-id:reply-to; bh=SpbCpqNBSJofAC/j40Ob39O2Bo6y66FzUZzYjwnngqA=; b=lIGJmcd3knd086/RuLsUW9VNdvpDugj+X8yqgnQB2AgzaF4AfP1Uuc+E2QoZvT156z O7Zzexuy44uRtgybPnQNJ0rdwODxlhQoW6brKVuiZvmKFmM7QwVWU99ddXCcxOXsnXXw eGhyvyjR8/HTZdAgxm5y3r78UJauK61zzhJKfjvfEobTw7q4k+luZNU23KQx4n/SnCO4 Leb15aW8H8M9ItzdX//h4pYF9X7+tgLH8iBHuR7McA2SYKr8HWv5l6ID1NoBVE54jf1s i2s6ZQEzo1WsE5H6+rX0q+MH8kU7AIjWvsftvk3v6xgFA1isbP7SGp+pGK24Ypmbr2TB kzQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701992629; x=1702597429; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:cc:to:from:subject:message-id:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=SpbCpqNBSJofAC/j40Ob39O2Bo6y66FzUZzYjwnngqA=; b=a7wj5NkjY+4rzuHTHx3742VmtnVQE0WEiNfxUrfRfUOC389G9qKBNp4toElIl3vQcG ykKZ3IRnhPqdOsNAtEI1xhV8KnZf1ycvd90ldD/mMFoNfHxSfjPL4wNMWi+imnYyq9Ne SJ5txqQp3WgTHjYweXrScVux2lGrM3iqrH7I2/eYx705wh7Cj3K4bLHVTIUqTGKzMVbi YQ0xnarFZQThfObhBgVD2lnS+FVcWlH1Q2dbOSBhClJ8cKVehu2kSs7eLfhXXZNhJRt/ +Rkl753ch4PJlw7x1rHQ8dxzwL4lDY2uqFtZIkeOrkqVuJBrR57+GPnGNcU3BanR5eLK r3zA== X-Gm-Message-State: AOJu0Yz0rgxuyotS7PkfnOX6mBmtAp3EOVuWFqpoZDSeSP5vFgKvImqv b5surWCYTReJN1kjcN8/z9AhkQ== X-Google-Smtp-Source: AGHT+IGqg6aslL/QItxuSzefCfcfMsV2+e3k4+ZmaqztQOzK9iTVLxwbNvGQsqYBSUSCgIQtuhg2Ig== X-Received: by 2002:a17:902:d384:b0:1cf:7683:93e with SMTP id e4-20020a170902d38400b001cf7683093emr3399574pld.24.1701992629447; Thu, 07 Dec 2023 15:43:49 -0800 (PST) Received: from [172.18.10.36] ([12.126.244.130]) by smtp.gmail.com with ESMTPSA id ik2-20020a170902ab0200b001cfc9c926b7sm390359plb.75.2023.12.07.15.43.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Dec 2023 15:43:49 -0800 (PST) Message-ID: <8d5cce64d7413eff04c5595a0a80d2b5a809e2fe.camel@j-davis.com> Subject: Re: micro-optimizing json.c From: Jeff Davis To: Nathan Bossart , Joe Conway Cc: Tom Lane , Andrew Dunstan , Davin Shearer , PostgreSQL-development Date: Thu, 07 Dec 2023 15:43:47 -0800 In-Reply-To: <20231207231251.GB3359478@nathanxps13> References: <20231207231251.GB3359478@nathanxps13> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.44.4-0ubuntu2 MIME-Version: 1.0 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Thu, 2023-12-07 at 17:12 -0600, Nathan Bossart wrote: > Here's a patch that removes a couple of strlen() calls that showed up > prominently in perf for a COPY TO (FORMAT json) on 110M integers.=C2=A0 O= n > my > laptop, I see a 20% speedup from ~23.6s to ~18.9s for this test. Nice improvement. The use of (len =3D ...) in a conditional is slightly out of the ordinary, but it makes the conditionals a bit simpler and you have a comment, so it's fine with me. I wonder, if there were an efficient cast from numeric to text, then perhaps you could avoid the strlen() entirely? Maybe there's a way to use a static buffer to even avoid the palloc() in get_str_from_var()? Not sure these are worth the effort; just brainstorming. In any case, +1 to your simple change. Regards, Jeff Davis