From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Mattias =?UTF-8?Q?Engdeg=C3=A5rd?= Newsgroups: gmane.emacs.bugs Subject: bug#58168: string-lessp glitches and inconsistencies Date: Thu, 6 Oct 2022 11:05:04 +0200 Message-ID: References: <7824372D-8002-4639-8AEE-E80A6D5FEFC6@gmail.com> <83czbef6le.fsf@gnu.org> <6CB805F6-89EE-4D7C-A398-F29698733A42@gmail.com> <83h70oce4k.fsf@gnu.org> <83tu4mais1.fsf@gnu.org> <83wn9gw2sp.fsf@gnu.org> Mime-Version: 1.0 (Mac OS X Mail 14.0 \(3654.120.0.1.13\)) Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="7718"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 58168@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Oct 06 11:47:29 2022 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ogNTV-0001tq-90 for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 06 Oct 2022 11:47:29 +0200 Original-Received: from localhost ([::1]:41016 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ogNTU-000749-2f for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 06 Oct 2022 05:47:28 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:53738) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ogNIS-0001s6-Kf for bug-gnu-emacs@gnu.org; Thu, 06 Oct 2022 05:36:08 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:59928) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ogNIQ-0006lF-NP for bug-gnu-emacs@gnu.org; Thu, 06 Oct 2022 05:36:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1ogNIQ-0004Nn-I5 for bug-gnu-emacs@gnu.org; Thu, 06 Oct 2022 05:36:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Mattias =?UTF-8?Q?Engdeg=C3=A5rd?= Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 06 Oct 2022 09:36:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 58168 X-GNU-PR-Package: emacs Original-Received: via spool by 58168-submit@debbugs.gnu.org id=B58168.166504892116791 (code B ref 58168); Thu, 06 Oct 2022 09:36:02 +0000 Original-Received: (at 58168) by debbugs.gnu.org; 6 Oct 2022 09:35:21 +0000 Original-Received: from localhost ([127.0.0.1]:59005 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ogNHl-0004Mk-0G for submit@debbugs.gnu.org; Thu, 06 Oct 2022 05:35:21 -0400 Original-Received: from mail-lj1-f169.google.com ([209.85.208.169]:35567) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ogNHe-0004MB-UM for 58168@debbugs.gnu.org; Thu, 06 Oct 2022 05:35:18 -0400 Original-Received: by mail-lj1-f169.google.com with SMTP id m14so1572715ljg.2 for <58168@debbugs.gnu.org>; Thu, 06 Oct 2022 02:35:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:sender:from:to:cc:subject :date; bh=aP7R+KsjxngIlXx0VZV8oIyL6IW8I0ZvrJ5jSn/8370=; b=AVQtrZ8HCts+8t9nFRID/hoVVw2dBZUHz6pjxfTBPanK43sphXn/x3ReVL67oXbKFF OYc5Qcqiq2mK8ytrIcu4ZW7WYbrPgtce/tZtw7OQeDNnq7O2eZOcj6dUcBwD+4eHuowO Y7eYyl3REvcF0mpbhqbK8WWsJoDx6LRew0AbIalxaW208iAO9XaCAypg5/AMZbdbQZCx ULOWN5dskD+IBXO4XRy8iLiMy75BVyMcxtnvPB0xE5FAP4NE1qGUqMrhqEy15fwDbZcp NZ4JikSfpp8mYCLHN4NQToyYnXIjFEfAUd8uyT9TfYS3+f6bhT5bhjc+MbOBbz4Me+0w MnhQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:sender:x-gm-message-state :from:to:cc:subject:date; bh=aP7R+KsjxngIlXx0VZV8oIyL6IW8I0ZvrJ5jSn/8370=; b=niHg+QG0KkEskfJzSawDnGTRAE46L16QPdKQOn7bqDT02xbmhc5CpnLD0skjDC6NB0 F/Y2pU0kmP31GuDdk86zg8C7VSvWXbNG8euRAYYvA9edeSMbtaedp6Qsl+UztMAVypqx DPmwmRPPPQDnIo9shHya11E5nSOCCQEQbcIQi61VySLGs7dnIuqQB49xb+a9bZaHh/de AhaDYbf/oeUAgEBIKYyT/hAfsZ3447X3aiW5B0oB6FZm2KPebywu9UT+D4rpKMGjX18X xFkG/VSBlK9El0eAq+9ZrVefRGuBMyIdPIv1mXPpToYtHlBHUOoFeO0qGkWQeVMkXk79 VLIA== X-Gm-Message-State: ACrzQf04oMKI/vklj9awL3NhI2YNojw6yUnAtCpEXtIAq8+0O6gt+XvO uNfVh8uQcGE9fpS4qNcFJhqoIy/3+foJdQ== X-Google-Smtp-Source: AMsMyM7DrXhjsJL2oFxlHpmwmlUIN34xeS4C4kzqAfJIW+OMoSOaxdtrZ0aYDMWE+9aewDp8ugx7yw== X-Received: by 2002:a05:651c:210e:b0:26c:7db3:17da with SMTP id a14-20020a05651c210e00b0026c7db317damr1396437ljq.220.1665048908752; Thu, 06 Oct 2022 02:35:08 -0700 (PDT) Original-Received: from smtpclient.apple (c188-150-171-209.bredband.tele2.se. [188.150.171.209]) by smtp.gmail.com with ESMTPSA id g28-20020a2e391c000000b0026ddea22596sm1204567lja.37.2022.10.06.02.35.07 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 06 Oct 2022 02:35:08 -0700 (PDT) In-Reply-To: <83wn9gw2sp.fsf@gnu.org> X-Mailer: Apple Mail (2.3654.120.0.1.13) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:244624 Archived-At: 4 okt. 2022 kl. 07.55 skrev Eli Zaretskii : > If the fact that string=3D says strings are not equal, but = string-lessp > says they are equal, is what bothers you, we could document that > results of comparing unibyte and multibyte strings are unspecified, or > document explicitly that string=3D and string-lessp behave differently > in this case. (It's not just string=3D but `equal` since they use the same = comparison.) But it's just a part of a set of related problems: * string< / string=3D inconsistency * undesirable string< ordering (unibyte strings are treated as Latin-1) * bad string< performance=20 Ideally we should be able to do something about all three at the same = time since they are interrelated. At the very least it's worth a try. Just documenting the annoying parts won't make them go away -- they = still have to be coded around by the user, and it doesn't solve any = performance problems either. > I see no reason to worry about 100% consistency here: the order > is _really_ undefined in these cases, and trying to make it defined > will not produce any tangible gains, Yes it would: better performance and wider applicability. Even when the = order isn't defined the user expects there to be some order between = distinct strings. > Once again, slowing down string-lessp when raw-bytes are involved > shouldn't be a problem. So, if memchr finds a C0 or C1 in a string, > fall back to a slower comparison. memchr is fast enough to not slow > down the "usual" case. Would that be a good solution? There is no reason a comparison should need to look beyond the first = mismatch; anything else is just algorithmically slow. Long strings are = likely to differ early on. Any hack that has to special-case raw bytes = will add costs. The best we can hope for is hand-written vectorised code that does = everything in one pass but it's still slower than just a memcmp. Even then our chosen semantics make that more difficult (and slower) = than it needs to be: for example, we cannot assume that any byte with = the high bit set indicates a mismatch when comparing unibyte strings = with multibyte, since we equate unibyte chars with Latin-1. It's a = decision that we will keep paying for. > Alternatively, we could introduce a new primitive which could assume > multibyte or plain-ASCII unibyte strings without checking, and then > code which is sure raw-bytes cannot happen, and needs to compare long > strings, could use that for speed. That or variants thereof are indeed alternatives but users would be = forgiven to wonder why we don't make what we have fast instead? > E.g., are you saying that unibyte strings that are > pure-ASCII also cause performance problems? They do because we have no efficient way of ascertaining that they are = pure-ASCII. The long-term solution is to make multibyte strings the = default in more cases but I'm not proposing such a change right now. I'll see to where further performance tweaking of the existing code can = take us with a reasonable efforts, but there are hard limits to what can = be done. And thank you for your comments!