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.96) (envelope-from ) id 1vR1vq-004bTO-2A for pgsql-hackers@arkaria.postgresql.org; Thu, 04 Dec 2025 05:31:11 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vR1vp-000iBK-2I for pgsql-hackers@arkaria.postgresql.org; Thu, 04 Dec 2025 05:31:10 +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.96) (envelope-from ) id 1vR1vp-000iBC-1P for pgsql-hackers@lists.postgresql.org; Thu, 04 Dec 2025 05:31:09 +0000 Received: from mail-qk1-x742.google.com ([2607:f8b0:4864:20::742]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1vR1vn-0032io-2g for pgsql-hackers@lists.postgresql.org; Thu, 04 Dec 2025 05:31:09 +0000 Received: by mail-qk1-x742.google.com with SMTP id af79cd13be357-8b2dec4d115so53681585a.0 for ; Wed, 03 Dec 2025 21:31:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1764826265; x=1765431065; darn=lists.postgresql.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=016Cf0EjwQMr6bSlMdmOX0ge4pCx6XGHR6//919AHoc=; b=KTRR5z47vnxxeSzrghx9rD1F7IvP4JjsVyoecsFYoiZVttS9fIIdCFHQBnYxgCky5E og+37UnYLUsDze1PGB0KyRQv9N6snTwZOWsoC4cypBzAjDTUB+AqAxQqN4eU3s5EGTY1 wjq717y+ufUTFKNlcc/ZDlzPvp5FeR5JloGhBw3d/5NXj4tChF45THjwcvEM9JZG8vI3 qRsqkYpykdH2Zh2KJ4n8TasYv3Sg7oPI6odsk8eiB0pxX1z4U6CUPyV2n+xPzGLcQGOJ fP/mJBkYYRol5+yR3xmcamt3aeSRzHYEqdY8MMjVaKiTeCmsIp3VS9pe6rP0zUKwxhm5 3YTw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764826265; x=1765431065; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=016Cf0EjwQMr6bSlMdmOX0ge4pCx6XGHR6//919AHoc=; b=JTkzSxhs0SL33U0Sl83OSAo8Xqp20FNqK+zHbhkALttKQcE6XjCVFjGJLjHRPnYKcC //jIV1eXpOr8TSMBa5Cf6Ux4/+X7KEvnN+wQGk4Sf9e+l8l+XG+DMtMAkPr4d2nYUDSn TKHDRgTugBU+G9TY1HFPA789vfZiUetQpGva5pIJ0FBC3+tkn6lZ5oZ2VCr5+YLbKrEA jMHx9oxT+j9k1dzYCpPEVmiyEibVYss9ahmvR0+8mg4sueMjrro/N9O7/LTUvtfVtyTH zk8TcexLeBfHo8gkayUZNLF4XNQU7nPOPGnJjtIPuKmSCp5M/CdYzaW69R5AvN7WvKxp PQLA== X-Forwarded-Encrypted: i=1; AJvYcCWniAeylol7OoUVdxXvbHoJxb5gjkBOl59Ud42Qpibi4ZABCVKBfyPWDoq7Ke6aADk+PTps9bJae0IURlD+@lists.postgresql.org X-Gm-Message-State: AOJu0YzZDcanB9qubQF4yDSKHmAFq9gaOnLnUv5WM9xOTc/neFqZ3kZc xB8w5GDvY8xrd6jSQHVNrHagJb5EMB/IFae+hFXiiDCoLwNmG8/uGvb1yJrXtOrCV3YXSyN8JOj hf+AZENJ46i1THSTk1rk0sW7J+UtAsfU= X-Gm-Gg: ASbGnctFMV9cxafiqAJrso1RAD+6OBBuBRAfbdEOy2sC9WBUpe9noz6S9f0hh1zMX4c cruHMyhAWXABJLPhxMDPyjEKHGgMNzJoNOuZitf/JmIaNlHEwQ+COr6BPaTls8zPK+dPdsFMR9J AK5UkWql0GDoPBHZ+ieWUv4hlGj8v6GVrPq9hXy/DRS0IVAe1lD1/BdshqfD1DXlz/ZyQwGFmAj c10vG46wnPEv+m3TjbBjFR3plxyJEXmVgD+QJoJ9DNlk+4ftG6CacIBpgw8wYmGoc4bqPsWK+Ql VZj2a0+Y8LJ7et7zDEV7Pp4wiomHiJxvyc+YiVYSHN+tru/ZLUKlvMpE99V6gMpImxztLyxbpzY d6BEkh8UqncBg9/E= X-Google-Smtp-Source: AGHT+IE2D72yTS3vftTib5kli6S3n9uRJYsEsG6HekGm2gswZYNsTqD2gR5tGJuy8dr0D+cMuViUcrGarD7kfuoYkd8= X-Received: by 2002:a05:620a:1a1d:b0:8b5:ccd1:1a0f with SMTP id af79cd13be357-8b5e782fe5bmr680427485a.90.1764826265592; Wed, 03 Dec 2025 21:31:05 -0800 (PST) MIME-Version: 1.0 References: <269A8FB9-6D43-43CF-A6FE-52D28CBDB8A9@Outlook.com> <606C775A-4C1A-482B-BE7D-2E7A46AE14B9@gmail.com> In-Reply-To: <606C775A-4C1A-482B-BE7D-2E7A46AE14B9@gmail.com> From: John Naylor Date: Thu, 4 Dec 2025 12:30:52 +0700 X-Gm-Features: AWmQ_bnuC_QZkkj06VFegG1V6SZwZVHCle6zEmd9J-Q9L3iGtLOqZFwJdW3PpXw Message-ID: Subject: Re: tuple radix sort To: Chao Li Cc: Chengpeng Yan , "pgsql-hackers@lists.postgresql.org" , Peter Geoghegan Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Wed, Dec 3, 2025 at 3:22=E2=80=AFPM Chao Li wro= te: > I played with this again today and found an optimization that seems to dr= amatically improve the performance: > > ``` > +static void > +radix_sort_tuple(SortTuple *begin, size_t n_elems, int level, Tuplesorts= tate *state) > +{ > + RadixPartitionInfo partitions[256] =3D {0}; > + uint8_t remaining_partitions[256] =3D {0}; > ``` > > Here partitions and remaining_partitions are just temporary buffers, allo= cating memory from stack and initialize them seems slow. By passing them as= function parameters are much faster. See attached diff for my change. The lesson here is: you can make it as fast as you like if you accidentally blow away the state that we needed for this to work correctly. -- John Naylor Amazon Web Services