Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oRPnz-0006RQ-BS for pgsql-hackers@arkaria.postgresql.org; Fri, 26 Aug 2022 03:14:47 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1oRPny-0008UF-1X for pgsql-hackers@arkaria.postgresql.org; Fri, 26 Aug 2022 03:14:46 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oRPnx-0008U5-Mc for pgsql-hackers@lists.postgresql.org; Fri, 26 Aug 2022 03:14:45 +0000 Received: from mail-pj1-x102b.google.com ([2607:f8b0:4864:20::102b]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1oRPnu-0001ZS-3c for pgsql-hackers@postgresql.org; Fri, 26 Aug 2022 03:14:44 +0000 Received: by mail-pj1-x102b.google.com with SMTP id ds12-20020a17090b08cc00b001fae6343d9fso6941682pjb.0 for ; Thu, 25 Aug 2022 20:14:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc; bh=W2xDdUf0XI0H3BE+gJWfytPt3Lwi+e/6OJObtnZ+wJg=; b=dP5aRG44ugM67nfcfFZklyYJ3teD84OaKUw8ZqFqqOthCCK8Hkma3Qm7WOjt5pewsj 6sDjAc4KNp8W91VUtu2Wmx1j5DcDE2yUq2IO6tKMJFoypF4daOZFJ8RCvZn1vbfnlDiF eSXhqNH+aqaZI3VI0KkYBVQzvptS/sTlcjAOwZlAi7IJflM0z6lTw88Nx9olQzkDgM5z IO5Nt7SrbnGVlYZtBjtNVWa8oP2kC1cV80X5WWOd5ayKO0nnYo5NGzD+L7d24Xj2iYlQ JAZnr1B35aQ5Puo0Dzmh6Iea0IX6t9GstTTFlAOaYWMjb0eg18hVjfagoUPvydSgV4/u 8GzA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc; bh=W2xDdUf0XI0H3BE+gJWfytPt3Lwi+e/6OJObtnZ+wJg=; b=Jrdq/y5av+mDuPZaTVtYu9Gvrb0Z27vXk6dW4h29FLWIk8I4hoUwNMk7RbBslSGjsp TVzjJpQmu84aNrC6mDgSyM9Gsl1r9D8+7r815Gk6qCNENed0GsEGEj8iQAwHWbn6VqK/ 5KvgetqvQv3CxfmSozDxKVaSxI4xD8aQQ4a6kK1zBP4KP4YD62uWoi0XczSebjwVZV4H aZKaJeuk/Q12buSevPV7GBiYxD4Alrh2727ZoovCUM2LKpPw0mjhiir1IWWX1gieDWlY nrrmETkcBWlB0us8xPEkIqYa9D4ibbBx/46LHkPPghMyG2DvFFmOVeZzlV49o3kvf4E+ +gpA== X-Gm-Message-State: ACgBeo3FLxKPz+ziKFfvURJBQ9v+k+ejYLiQBiY2qF0yMRo0vP4Heq4P c1QDlRfDhbpl91xEuAkYqMs= X-Google-Smtp-Source: AA6agR5gU/Bp2SYShzcm83w0ifAnxEgyjkYb/NIgwAcoBnuZ5A/zPzyOn5TwOUfsOZMDEgDMOE9/xg== X-Received: by 2002:a17:90a:970c:b0:1fb:b9fb:6dba with SMTP id x12-20020a17090a970c00b001fbb9fb6dbamr2126637pjo.221.1661483680836; Thu, 25 Aug 2022 20:14:40 -0700 (PDT) Received: from nathanxps13 ([50.47.162.83]) by smtp.gmail.com with ESMTPSA id c14-20020a655a8e000000b0041bfa382dfesm315373pgt.67.2022.08.25.20.14.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Aug 2022 20:14:40 -0700 (PDT) Date: Thu, 25 Aug 2022 20:14:37 -0700 From: Nathan Bossart To: John Naylor Cc: Andres Freund , Tom Lane , Jelte Fennema , "pgsql-hackers@postgresql.org" , Merlin Moncure , Andrew Dunstan , Stephen Frost Subject: Re: [PATCH] Optimize json_lex_string by batching character copying Message-ID: <20220826031437.GA1466128@nathanxps13> References: <20220819204215.GA397534@nathanxps13> <20220821054733.GA780295@nathanxps13> <20220822212229.GA1129243@nathanxps13> <20220823033236.GA1204962@nathanxps13> <20220823171546.GA1207981@nathanxps13> <20220824165603.GA1302810@nathanxps13> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Thu, Aug 25, 2022 at 01:35:45PM +0700, John Naylor wrote: > - For the following comment, pgindent will put spaced operands on a > separate line which is not great for readability. and our other > reference to the Stanford bithacks page keeps the in-page link, and I > see no reason to exclude it -- if it goes missing, the whole page will > still load. So I put back those two details. > > + * To find bytes <= c, we can use bitwise operations to find > bytes < c+1, > + * but it only works if c+1 <= 128 and if the highest bit in v > is not set. > + * Adapted from > + * https://graphics.stanford.edu/~seander/bithacks.html#HasLessInWord This was just unnecessary fiddling on my part, sorry about that. > +test_lfind8_internal(uint8 key) > +{ > + uint8 charbuf[LEN_WITH_TAIL(Vector8)]; > + const int len_no_tail = LEN_NO_TAIL(Vector8); > + const int len_with_tail = LEN_WITH_TAIL(Vector8); > + > + memset(charbuf, 0xFF, len_with_tail); > + /* search tail to test one-byte-at-a-time path */ > + charbuf[len_with_tail - 1] = key; > + if (key > 0x00 && pg_lfind8(key - 1, charbuf, len_with_tail)) > + elog(ERROR, "pg_lfind8() found nonexistent element <= '0x%x'", key - 1); > + if (key < 0xFF && !pg_lfind8(key, charbuf, len_with_tail)) > + elog(ERROR, "pg_lfind8() did not find existing element <= '0x%x'", key); > + if (key < 0xFE && pg_lfind8(key + 1, charbuf, len_with_tail)) > + elog(ERROR, "pg_lfind8() found nonexistent element <= '0x%x'", key + 1); > + > + memset(charbuf, 0xFF, len_with_tail); > + /* search with vector operations */ > + charbuf[len_no_tail - 1] = key; > + if (key > 0x00 && pg_lfind8(key - 1, charbuf, len_no_tail)) > + elog(ERROR, "pg_lfind8() found nonexistent element <= '0x%x'", key - 1); > + if (key < 0xFF && !pg_lfind8(key, charbuf, len_no_tail)) > + elog(ERROR, "pg_lfind8() did not find existing element <= '0x%x'", key); > + if (key < 0xFE && pg_lfind8(key + 1, charbuf, len_no_tail)) > + elog(ERROR, "pg_lfind8() found nonexistent element <= '0x%x'", key + 1); > +} nitpick: Shouldn't the elog() calls use "==" instead of "<=" for this one? Otherwise, 0001 looks good to me. -- Nathan Bossart Amazon Web Services: https://aws.amazon.com