-
-
Notifications
You must be signed in to change notification settings - Fork 700
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
std.algorithm.searching: no mapping-specialization for extremum #5001
Conversation
@safe pure nothrow unittest | ||
private auto extremum(alias selector = "a < b", Range)(Range r) | ||
if (isInputRange!Range && !isInfinite!Range && | ||
!is(typeof(unaryFun!selector(ElementType!(Range).init)))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem here is that with string mixins a[0]
can be a valid unary and binary function:
pragma(msg, is(typeof(unaryFun!`a[0]`([0])))); // true
pragma(msg, is(typeof(binaryFun!`a[0]`([0], [0])))); // true
952b292
to
fe8460d
Compare
3221ab4
to
517e56e
Compare
{ | ||
if (selectorFun(r.front, extremeElement)) | ||
{ | ||
extremeElement = r.front; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this appears uncovered, why?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because most tests were using orderd arrays and the default predicate. It's easy to cover though:
517e56e
to
58b1c0b
Compare
… performance improvements
I added this to the changelog. (there seems to be some whitespace issues in ddoc, but that's the fault of the changelog generation script) |
FYI: This is a new security feature to protect from unapproved changes sneaking in. |
@wilzbach cool! so what did I do wrong? |
Nothing - I added the changelog entry. |
Ah, got it. So now I'll re-review and reapply. |
Yep, that was the idea behind this feature. The auto-tester allows such "silent changes". |
Performance improvements for `std.algorithm.searching.{min,max}Element` | ||
|
||
$(REF minElement, std, algorithm, searching) and $(REF maxElement, std, algorithm, searching) | ||
are now a lot faster as a special path for the identity case is provided. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"a lot" -> "considerably"
better yet:
"considerably (almost 2x in microbenchmarks)" (or whatever)
i.e. we're trying to avoid colloquialisms
thx!! |
Simple "one char" change in the changelog. Sorry
PR: dlang/tools#223 |
MapType extremeElementMapped = mapFun(extremeElement); | ||
|
||
static if (isRandomAccessRange!Range && hasLength!Range) | ||
// direct access via a random access range is faster | ||
static if (isRandomAccessRange!Range) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removing the check for length here will allow an infinite random access range to use this branch
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
!isInfinite!Range
is an excluding constraint above as extremum
will be an endless loop on infinite ranges.
alias selectorFun = binaryFun!selector; | ||
|
||
// direct access via a random access range is faster | ||
static if (isRandomAccessRange!Range) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
needs a check for length here too
@JackStouffer I had another look at this PR and discovered that there were still some uncovered bits due to the combinatorial explosion of the alias (aka non-string comparison) approach. |
In #4265 I showed that
extremum
(akaminElement
andmaxElement
) can be made a lot faster if we provide a special path for the identity case, because the compiler can then make use of SSE instructions.In theory the compiler should be smart enough to figure it out himself, but well neither dmd nor ldc are that smart :/
For reference here are the benchmarks from #4265:
Source for benchmarks: http://sprunge.us/QSWP
This PR does the specialization via overloads whereas #4265 does them via comparison of strings.