* [Emacs-diffs] trunk r117765: Add vectors support to Fsort.
@ 2014-08-29 10:46 Eli Zaretskii
2014-08-29 14:21 ` Jordon Biondo
2014-08-29 21:19 ` Change Emacs 'sort' API to use three-way comparison Paul Eggert
0 siblings, 2 replies; 15+ messages in thread
From: Eli Zaretskii @ 2014-08-29 10:46 UTC (permalink / raw)
To: Dmitry Antipov; +Cc: emacs-devel
Thanks for doing this.
This change should have a corresponding NEWS entry.
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [Emacs-diffs] trunk r117765: Add vectors support to Fsort.
2014-08-29 10:46 [Emacs-diffs] trunk r117765: Add vectors support to Fsort Eli Zaretskii
@ 2014-08-29 14:21 ` Jordon Biondo
2014-08-29 15:41 ` Dmitry Antipov
2014-08-29 21:19 ` Change Emacs 'sort' API to use three-way comparison Paul Eggert
1 sibling, 1 reply; 15+ messages in thread
From: Jordon Biondo @ 2014-08-29 14:21 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: Dmitry Antipov, emacs-devel
fns-tests.el is failing on trunk for me. I get the Re-entering top level after C stack overflow error, then: Fatal error 11: Segmentation faultAbort trap: 6, if I try to do anything else. It looks like qsort_r needs special treatment on darwin and bsd systems.
For now I’m just undefining HAVE_QSORT_R.
Thanks,
Jordon
On Aug 29, 2014, at 6:46 AM, Eli Zaretskii <eliz@gnu.org> wrote:
> Thanks for doing this.
>
> This change should have a corresponding NEWS entry.
>
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [Emacs-diffs] trunk r117765: Add vectors support to Fsort.
2014-08-29 14:21 ` Jordon Biondo
@ 2014-08-29 15:41 ` Dmitry Antipov
2014-08-29 15:50 ` Jordon Biondo
0 siblings, 1 reply; 15+ messages in thread
From: Dmitry Antipov @ 2014-08-29 15:41 UTC (permalink / raw)
To: Jordon Biondo; +Cc: emacs-devel
On 08/29/2014 06:21 PM, Jordon Biondo wrote:
> fns-tests.el is failing on trunk for me. I get the Re-entering top level
> after C stack overflow error, then: Fatal error 11: Segmentation fault
> Abort trap: 6, if I try to do anything else. It looks like qsort_r needs
> special treatment on darwin and bsd systems.
Oops. I have a VM with FreeBSD 10.0 and will take a look.
BTW, what is your output from the following program:
#include <stdio.h>
#include <sys/resource.h>
int
main (int argc, char *argv[])
{
struct rlimit rlim;
getrlimit (RLIMIT_STACK, &rlim);
printf ("%ld %ld\n", rlim.rlim_cur, rlim.rlim_max);
return 0;
}
Running as root, I get:
536870912 536870912
512 Mb stack? I just don't believe in that.
Dmitry
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [Emacs-diffs] trunk r117765: Add vectors support to Fsort.
2014-08-29 15:41 ` Dmitry Antipov
@ 2014-08-29 15:50 ` Jordon Biondo
2014-08-29 16:34 ` Dmitry Antipov
0 siblings, 1 reply; 15+ messages in thread
From: Jordon Biondo @ 2014-08-29 15:50 UTC (permalink / raw)
To: Dmitry Antipov; +Cc: emacs-devel
On Aug 29, 2014, at 11:41 AM, Dmitry Antipov <dmantipov@yandex.ru> wrote:
> Oops. I have a VM with FreeBSD 10.0 and will take a look.
>
> BTW, what is your output from the following program:
Thanks,
8720000 67104768 is my output.
Also, I sent a report and hacky patch to bug-gnu-emacs about it with further information.
Thanks,
Jordon
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [Emacs-diffs] trunk r117765: Add vectors support to Fsort.
2014-08-29 15:50 ` Jordon Biondo
@ 2014-08-29 16:34 ` Dmitry Antipov
2014-08-29 16:43 ` Jordon Biondo
0 siblings, 1 reply; 15+ messages in thread
From: Dmitry Antipov @ 2014-08-29 16:34 UTC (permalink / raw)
To: Jordon Biondo; +Cc: emacs-devel
On 08/29/2014 07:50 PM, Jordon Biondo wrote:
> 8720000 67104768 is my output.
Good, 8720000 looks like a valid limit.
Can you also verify that running an endless recursion
with huge max-lisp-eval-depth, e.g.:
(setq max-specpdl-size 83200000
max-lisp-eval-depth 640000)
(defun f1 () (f1))
(f1)
doesn't crash but throws you to a top-level editing loop?
Thanks,
Dmitry
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [Emacs-diffs] trunk r117765: Add vectors support to Fsort.
2014-08-29 16:34 ` Dmitry Antipov
@ 2014-08-29 16:43 ` Jordon Biondo
2014-08-29 18:31 ` Stefan Monnier
0 siblings, 1 reply; 15+ messages in thread
From: Jordon Biondo @ 2014-08-29 16:43 UTC (permalink / raw)
To: Dmitry Antipov; +Cc: emacs-devel
[-- Attachment #1: Type: text/plain, Size: 492 bytes --]
On Aug 29, 2014, at 12:34 PM, Dmitry Antipov <dmantipov@yandex.ru> wrote:
> doesn't crash but throws you to a top-level editing loop?
With this I get the same Error, Re-entering top level after C stack overflow and I can keep editing for a time.
I will seg fault soon after, however. I haven’t nailed down exactly what causes the seg fault after, but doing tab-completion in the mini buffer will seg fault if I run your code and get the overflow error first.
Thanks,
Jordon
[-- Attachment #2: Type: text/html, Size: 1275 bytes --]
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [Emacs-diffs] trunk r117765: Add vectors support to Fsort.
2014-08-29 16:43 ` Jordon Biondo
@ 2014-08-29 18:31 ` Stefan Monnier
2014-08-29 22:53 ` Dmitry Antipov
0 siblings, 1 reply; 15+ messages in thread
From: Stefan Monnier @ 2014-08-29 18:31 UTC (permalink / raw)
To: Jordon Biondo; +Cc: Dmitry Antipov, emacs-devel
>> doesn't crash but throws you to a top-level editing loop?
> With this I get the same Error, Re-entering top level after C stack overflow
> and I can keep editing for a time.
> I will seg fault soon after, however. I haven’t nailed down exactly what
> causes the seg fault after, but doing tab-completion in the mini buffer will
> seg fault if I run your code and get the overflow error first.
Maybe the GC doesn't scan the altstack?
Stefan
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [Emacs-diffs] trunk r117765: Add vectors support to Fsort.
2014-08-29 18:31 ` Stefan Monnier
@ 2014-08-29 22:53 ` Dmitry Antipov
2014-08-31 0:18 ` Richard Stallman
0 siblings, 1 reply; 15+ messages in thread
From: Dmitry Antipov @ 2014-08-29 22:53 UTC (permalink / raw)
To: Stefan Monnier; +Cc: Jordon Biondo, emacs-devel
On 08/29/2014 10:31 PM, Stefan Monnier wrote:
> Maybe the GC doesn't scan the altstack?
This is not needed because the altstack is used only for SIGSEGV
handler (handle_sigsegv), which doesn't operate on GC'ed objects.
Dmitry
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [Emacs-diffs] trunk r117765: Add vectors support to Fsort.
2014-08-29 22:53 ` Dmitry Antipov
@ 2014-08-31 0:18 ` Richard Stallman
0 siblings, 0 replies; 15+ messages in thread
From: Richard Stallman @ 2014-08-31 0:18 UTC (permalink / raw)
To: Dmitry Antipov; +Cc: jordonbiondo, monnier, emacs-devel
[[[ To any NSA and FBI agents reading my email: please consider ]]]
[[[ whether defending the US Constitution against all enemies, ]]]
[[[ foreign or domestic, requires you to follow Snowden's example. ]]]
This is not needed because the altstack is used only for SIGSEGV
handler (handle_sigsegv), which doesn't operate on GC'ed objects.
This discussion suggests that that point ought to be mentioned
in comments in more places.
--
Dr Richard Stallman
President, Free Software Foundation
51 Franklin St
Boston MA 02110
USA
www.fsf.org www.gnu.org
Skype: No way! That's nonfree (freedom-denying) software.
Use Ekiga or an ordinary phone call.
^ permalink raw reply [flat|nested] 15+ messages in thread
* Change Emacs 'sort' API to use three-way comparison
2014-08-29 10:46 [Emacs-diffs] trunk r117765: Add vectors support to Fsort Eli Zaretskii
2014-08-29 14:21 ` Jordon Biondo
@ 2014-08-29 21:19 ` Paul Eggert
2014-08-29 21:51 ` David Kastrup
2014-08-30 14:23 ` Lars Ingebrigtsen
1 sibling, 2 replies; 15+ messages in thread
From: Paul Eggert @ 2014-08-29 21:19 UTC (permalink / raw)
To: Dmitry Antipov; +Cc: emacs-devel
One infelicity I noticed in the recent change to 'sort' in the trunk is
that the new implementation calls its predicate twice for each
comparison. This is because the Lisp API says the comparison function
returns a boolean (nil or non-nil), whereas qsort_r wants the comparison
function to return a ternary value (-1, 0, or 1). If the predicate is
expensive, the new Fsort can be twice as slow as the old. We could tune
it but I don't see how to get it any faster than 1.5x slower than
before, assuming random input and an expensive comparison function.
To fix this I propose changing the API for 'sort' so that its function
argument is no longer a predicate, but instead returns a negative
integer, 0, or a positive integer. For compatibility with old code, it
would treat nil as if it were nonpositive (thus requiring a reverse
comparison) and noninteger nonnil values as if they were positive. This
wouldn't be 100% upward-compatible, because if an existing predicate
returns a nonpositive integer to stand for 'true' there will be a silent
change to behavior, but I expect such usage is so rare that we don't
need to worry about it.
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: Change Emacs 'sort' API to use three-way comparison
2014-08-29 21:19 ` Change Emacs 'sort' API to use three-way comparison Paul Eggert
@ 2014-08-29 21:51 ` David Kastrup
2014-08-30 14:23 ` Lars Ingebrigtsen
1 sibling, 0 replies; 15+ messages in thread
From: David Kastrup @ 2014-08-29 21:51 UTC (permalink / raw)
To: emacs-devel
Paul Eggert <eggert@cs.ucla.edu> writes:
> One infelicity I noticed in the recent change to 'sort' in the trunk
> is that the new implementation calls its predicate twice for each
> comparison. This is because the Lisp API says the comparison function
> returns a boolean (nil or non-nil), whereas qsort_r wants the
> comparison function to return a ternary value (-1, 0, or 1). If the
> predicate is expensive, the new Fsort can be twice as slow as the old.
> We could tune it but I don't see how to get it any faster than 1.5x
> slower than before, assuming random input and an expensive comparison
> function.
Can someone give an executive summary why we would be using a "qsort_r"
here?
"sort" sorts a list. There is really not much of a point in not using a
mergesort here, resulting in a stable sort and requiring only a binary
comparison function.
Quicksorts make sense when sorting arrays.
--
David Kastrup
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: Change Emacs 'sort' API to use three-way comparison
2014-08-29 21:19 ` Change Emacs 'sort' API to use three-way comparison Paul Eggert
2014-08-29 21:51 ` David Kastrup
@ 2014-08-30 14:23 ` Lars Ingebrigtsen
2014-08-30 16:45 ` Paul Eggert
1 sibling, 1 reply; 15+ messages in thread
From: Lars Ingebrigtsen @ 2014-08-30 14:23 UTC (permalink / raw)
To: Paul Eggert; +Cc: Dmitry Antipov, emacs-devel
Paul Eggert <eggert@cs.ucla.edu> writes:
> One infelicity I noticed in the recent change to 'sort' in the trunk
> is that the new implementation calls its predicate twice for each
> comparison. This is because the Lisp API says the comparison function
> returns a boolean (nil or non-nil), whereas qsort_r wants the
> comparison function to return a ternary value (-1, 0, or 1). If the
> predicate is expensive, the new Fsort can be twice as slow as the old.
> We could tune it but I don't see how to get it any faster than 1.5x
> slower than before, assuming random input and an expensive comparison
> function.
Uhm. Why has somebody introduced a new sort that's slower than the old
sort?
As somebody who sorts a lot of things in Emacs, that sounds kinda
... bad.
--
(domestic pets only, the antidote for overdose, milk.)
bloggy blog http://lars.ingebrigtsen.no/
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: Change Emacs 'sort' API to use three-way comparison
2014-08-30 14:23 ` Lars Ingebrigtsen
@ 2014-08-30 16:45 ` Paul Eggert
2014-08-30 18:07 ` Lars Ingebrigtsen
0 siblings, 1 reply; 15+ messages in thread
From: Paul Eggert @ 2014-08-30 16:45 UTC (permalink / raw)
To: Lars Ingebrigtsen; +Cc: Dmitry Antipov, emacs-devel
Lars Ingebrigtsen wrote:
> Why has somebody introduced a new sort that's slower than the old
> sort?
In what sense is the new code slower? If you sort a list, the code is
the same as before.
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: Change Emacs 'sort' API to use three-way comparison
2014-08-30 16:45 ` Paul Eggert
@ 2014-08-30 18:07 ` Lars Ingebrigtsen
2014-08-30 18:14 ` Paul Eggert
0 siblings, 1 reply; 15+ messages in thread
From: Lars Ingebrigtsen @ 2014-08-30 18:07 UTC (permalink / raw)
To: Paul Eggert; +Cc: Dmitry Antipov, emacs-devel
Paul Eggert <eggert@cs.ucla.edu> writes:
> In what sense is the new code slower? If you sort a list, the code is
> the same as before.
I don't know anything about this code other than what you wrote about
it:
> We could tune it but I don't see how to get it any faster than 1.5x
> slower than before, assuming random input and an expensive comparison
> function.
It's slower in the sense that you said it's slower.
--
(domestic pets only, the antidote for overdose, milk.)
bloggy blog http://lars.ingebrigtsen.no/
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: Change Emacs 'sort' API to use three-way comparison
2014-08-30 18:07 ` Lars Ingebrigtsen
@ 2014-08-30 18:14 ` Paul Eggert
0 siblings, 0 replies; 15+ messages in thread
From: Paul Eggert @ 2014-08-30 18:14 UTC (permalink / raw)
To: Lars Ingebrigtsen; +Cc: Dmitry Antipov, emacs-devel
Lars Ingebrigtsen wrote:
> It's slower in the sense that you said it's slower.
Ah yes, sorry, I should have been clearer in my earlier remarks. The
new vector-sorting code can be considerably slower than sorting a list
of the same length, if the comparison predicate is expensive. But
existing code (which just sorts lists) should not be affected by this,
as the list-sorting code is the same as before.
Anyway, I'm looking into a fix for all this.
^ permalink raw reply [flat|nested] 15+ messages in thread
end of thread, other threads:[~2014-08-31 0:18 UTC | newest]
Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-08-29 10:46 [Emacs-diffs] trunk r117765: Add vectors support to Fsort Eli Zaretskii
2014-08-29 14:21 ` Jordon Biondo
2014-08-29 15:41 ` Dmitry Antipov
2014-08-29 15:50 ` Jordon Biondo
2014-08-29 16:34 ` Dmitry Antipov
2014-08-29 16:43 ` Jordon Biondo
2014-08-29 18:31 ` Stefan Monnier
2014-08-29 22:53 ` Dmitry Antipov
2014-08-31 0:18 ` Richard Stallman
2014-08-29 21:19 ` Change Emacs 'sort' API to use three-way comparison Paul Eggert
2014-08-29 21:51 ` David Kastrup
2014-08-30 14:23 ` Lars Ingebrigtsen
2014-08-30 16:45 ` Paul Eggert
2014-08-30 18:07 ` Lars Ingebrigtsen
2014-08-30 18:14 ` Paul Eggert
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).