Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:110145 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 92295 invoked from network); 12 May 2020 16:02:40 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 12 May 2020 16:02:40 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 268B51804F3 for ; Tue, 12 May 2020 07:39:20 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,FREEMAIL_REPLY, HTML_MESSAGE,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: No X-Envelope-From: Received: from mail-lf1-f47.google.com (mail-lf1-f47.google.com [209.85.167.47]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Tue, 12 May 2020 07:39:19 -0700 (PDT) Received: by mail-lf1-f47.google.com with SMTP id a4so10763555lfh.12 for ; Tue, 12 May 2020 07:39:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=vwHWwkWedO4izP6niTAYe8m9QH4uwUdrwVZTwvyEW7s=; b=Oh00A4s3W/PglivnF9lwcDounp7U1y8EULipi0LYptZ5aQcWiAVMNDaWFsaTAs2q+k A2iAMwNaZYEIjO03XFkqtxiv33QPflkA6RRRJ3IBzCFwRFb194VNEu/2YNrk46Ep2v+f 0UhLzs9FhWb3dQdkuMxzQM7PMn+ZxqwLyCgUvxiT68ideB37i3ddEEo/lJHM5PmAkEJV GtS5GE9IVx5uk927TbK7vt/t4j0BeVytac4cnwjkFHU/L9luxBVMLNn91A+3gLA1qOb8 mwv5BvtNbbuGcrIp9NkuQ6Tj2G73/HwqgkDeytgQ3z/S5NHjwoR4iDitM7plmkCeBoJX ccUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=vwHWwkWedO4izP6niTAYe8m9QH4uwUdrwVZTwvyEW7s=; b=M58Oe5yc+8qizOTxHE548CA5TiokPzZBxijGzJlSfeAV84Gfd59WUvgWE6V24TjEDB RXCrYun1g92bLuvRsQemP6PmXPAPCyjv8Cv2urzSVb9eGp/Y6BbJjX+IphPvPrqR28xY F9pk/U+W2zOJ/zAS4xyPt0VTGYQaJHaqFa02/sPgb/o5DtFSJan/Ziz5Klhn0ZgATzXc DyZ8a5lQ3sAMFJKy9yo3uXb09nrFzGTvCIatnGh6VtfJHYl5NjRy3778cLeeOWszj48S 6CvWMj75Evd2bmCBeqIaA4prf0oZNqp/+C7TdT1NoqNaqb04ax94HB/TmJXGINQMbixl yzfg== X-Gm-Message-State: AOAM531BA7k3h5ICZUZwlz36U5sBExRulhG6IJ7CIXcjNM3O1kmrAnq/ LdsLhVThBk976DL2RrLb7ss4ZJzkt8fPQnelAtQ= X-Google-Smtp-Source: ABdhPJyIb64yGypzMCj1SgB42yTLlweD7kbEKW6zudwG6TYfCLfXm7hd+VZu5/pUu2/Qvu+QjGrHonb5y+kpxYOMvgI= X-Received: by 2002:a19:8293:: with SMTP id e141mr14794382lfd.173.1589294357284; Tue, 12 May 2020 07:39:17 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Tue, 12 May 2020 16:39:01 +0200 Message-ID: To: Nicolas Grekas Cc: PHP internals Content-Type: multipart/alternative; boundary="0000000000009c0a6c05a5746d91" Subject: Re: [PHP-DEV] [RFC] Make sorting stable From: nikita.ppv@gmail.com (Nikita Popov) --0000000000009c0a6c05a5746d91 Content-Type: text/plain; charset="UTF-8" On Tue, May 12, 2020 at 4:29 PM Nicolas Grekas wrote: > Hi Nikita, > > Thanks for another nice RFC. > > This was previously discussed in https://externals.io/message/108841, but >> I >> figured it would make sense to create an RFC for this change: >> https://wiki.php.net/rfc/stable_sorting >> >> As before, the implementation approach is to stick with the existing qsort >> and use a fallback comparison criterion, which is cheap to implement >> internally. The obvious alternative is to use a stable base sort like >> Timsort. I gave this a quick try in >> https://github.com/php/php-src/pull/5559, >> and it does better in some cases (already sorted data) and worse in others >> (random data). I don't plan to pursue this direction personally. (It may >> also be interesting to use pdqsort as the unstable base, which should make >> the "already sorted" case faster.) >> > > IIRC, in PHP 5 sorting was stable. Then PHP 7 made it unstable. That was > something to account for when migrating - BC break inside. > In PHP 5 sorting was unstable. In PHP 7 sorting became stable for arrays with 16 elements or less. In PHP 8 sorting would become stable for *all* arrays. > On my side, I would very much prefer a new sorting flag, to be 200% sure > of the behavior: > sort($array, SORT_STABLE) > > That would allow ppl that don't care about stability to let the engine go > with the fastest algorithm. > I'd prefer to avoid an extra option. PHP is a high-level language, and the user should not have to concern themselves with sort stability considerations. I'd go for a flag if stable sorting had a huge perf impact. But as it doesn't, I don't see the point in an option. Regards, Nikita --0000000000009c0a6c05a5746d91--