florence
2017-2-16 22:16:41

@florence has joined the channel


mflatt
2017-2-16 22:47:06

@samth Looking at your sort change, I’m not sold on the idea of copying the code into a new module. I had in mind arranging for “racket/private/sort.rkt” to provide a generic function.


mflatt
2017-2-16 22:47:25

Do you have a sense of whether the specialized sort functions are worthwhile?


samth
2017-2-16 22:47:58

I think changing the implementation of sort to provide something generic would not be easy


samth
2017-2-16 22:48:12

because of both the specialization and the vector sorting


samth
2017-2-16 22:48:33

but I don’t know if specialization is worthwhile


samth
2017-2-16 22:50:13

yes, the specialization is worthwhile, I think


samth
2017-2-16 22:50:25

at least, this is a 2x performance difference:


samth
2017-2-16 22:50:38
#lang racket
(define l (build-list 1000000 (λ _ (random))))
(time (length (sort l <)))
(time (length (sort l (λ (x y) (< x y)))))

samth
2017-2-16 22:51:28

still significant if the function is (define lt <)


mflatt
2017-2-16 22:52:07

I don’t understand why (define lt <) matters, since it’s a dynamic test to pick a specialization


samth
2017-2-16 22:53:39

oh, hm


samth
2017-2-16 22:54:05

that was just a gc effect


samth
2017-2-16 22:54:07

sorry


mflatt
2017-2-16 22:54:28

Ok. I don’t think < versus (lambda (x y) (< x y)) is the right test, but I’ll investigate more in a while


samth
2017-2-16 22:55:23

lifting the function to the toplevel doesn’t really change the performance from the lambda version


mflatt
2017-2-16 22:56:02

That’s reassuring, but an indirect call to < will be different than an indirect call to (lambda (x y) (< x y))


samth
2017-2-16 22:59:25

removing the specialization entirely produces slower results for < than for (lambda ...)


samth
2017-2-16 23:00:42

so specialization is a non-trivial improvement — about a 60% slowdown when removed


samth
2017-2-16 23:00:50

for that benchmark, at least


mflatt
2017-2-16 23:42:08

@samth Ok, thanks for checking. Going back to the question of a generic sort, it looks like racket/private/base defines generic-sort, so maybe that could just be exported?


samth
2017-2-16 23:43:15

@mflatt I don’t see that in my copy of racket/private/base


samth
2017-2-16 23:43:45

or do you mean racket/private/sort?


mflatt
2017-2-16 23:43:49

Yes - should have been racket/private/sort


samth
2017-2-16 23:45:19

pulling that out would require restructuring racket/private/sort not to use a single define-values


samth
2017-2-16 23:45:36

which I think is there because it improved performance


mflatt
2017-2-16 23:46:03

? I mean just add generic-sort to the provide and then call generic-sort instead of sort in the expander


samth
2017-2-16 23:47:05

generic-sort is defined inside the (let () ...) that’s the RHS of the (define-values (sort vector-sort vector-sort!) ...)


samth
2017-2-16 23:48:04

I can try restructuring things, though


mflatt
2017-2-16 23:48:18

Ok, I keep forgetting that this module is old-school…. so add generic-sort to the define-values, add it to the final values, etc.


samth
2017-2-16 23:48:35

that won’t work — the simplifier can’t remove the rest of the define-values


samth
2017-2-16 23:48:45

and then we’re in the same place we are now


mflatt
2017-2-16 23:48:53

Ok, I see what you mean


samth
2017-2-16 23:49:50

I expect that the performance difference of having it all in one lexical scope is small, and will change before this code is actually shipped


mflatt
2017-2-16 23:51:34

I guess the let makes the macro implementation goes away when it’s expanded


mflatt
2017-2-16 23:51:58

Still, I think restructuring must be a better solution than copying the implementation


mflatt
2017-2-16 23:53:42

Ok if I merge the other parts of the PR?


samth
2017-2-16 23:54:12

yes


samth
2017-2-16 23:54:30

also, annoyingly, generic-sort operates on vectors of powers-of–2 size


samth
2017-2-16 23:54:40

so I won’t get this done tonight


mflatt
2017-2-17 00:23:22

@samth Beware that your commit exposed a bug in any-side-effects?, where the generic if case looked at thn and thn instead of thn and els


samth
2017-2-17 00:23:29

yes


samth
2017-2-17 00:23:35

I fixed that bug locally


samth
2017-2-17 00:23:51

I also pushed what I think is a bug-fix to make-match


samth
2017-2-17 00:24:03

but I don’t understand the code well enough to be sure


mflatt
2017-2-17 00:24:07

ok; I’ll include the repairs