@florence has joined the channel
@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.
Do you have a sense of whether the specialized sort functions are worthwhile?
I think changing the implementation of sort to provide something generic would not be easy
because of both the specialization and the vector sorting
but I don’t know if specialization is worthwhile
yes, the specialization is worthwhile, I think
at least, this is a 2x performance difference:
#lang racket
(define l (build-list 1000000 (λ _ (random))))
(time (length (sort l <)))
(time (length (sort l (λ (x y) (< x y)))))still significant if the function is (define lt <)
I don’t understand why (define lt <) matters, since it’s a dynamic test to pick a specialization
oh, hm
that was just a gc effect
sorry
Ok. I don’t think < versus (lambda (x y) (< x y)) is the right test, but I’ll investigate more in a while
lifting the function to the toplevel doesn’t really change the performance from the lambda version
That’s reassuring, but an indirect call to < will be different than an indirect call to (lambda (x y) (< x y))
removing the specialization entirely produces slower results for < than for (lambda ...)
so specialization is a non-trivial improvement — about a 60% slowdown when removed
for that benchmark, at least
@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?
@mflatt I don’t see that in my copy of racket/private/base
or do you mean racket/private/sort?
Yes - should have been racket/private/sort
pulling that out would require restructuring racket/private/sort not to use a single define-values
which I think is there because it improved performance
? I mean just add generic-sort to the provide and then call generic-sort instead of sort in the expander
generic-sort is defined inside the (let () ...) that’s the RHS of the (define-values (sort vector-sort vector-sort!) ...)
I can try restructuring things, though
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.
that won’t work — the simplifier can’t remove the rest of the define-values
and then we’re in the same place we are now
Ok, I see what you mean
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
I guess the let makes the macro implementation goes away when it’s expanded
Still, I think restructuring must be a better solution than copying the implementation
Ok if I merge the other parts of the PR?
yes
also, annoyingly, generic-sort operates on vectors of powers-of–2 size
so I won’t get this done tonight
@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
yes
I fixed that bug locally
I also pushed what I think is a bug-fix to make-match
but I don’t understand the code well enough to be sure
ok; I’ll include the repairs