Hey:
I was working on zend_qsort improvement. but I got a problem need
to be disscussed with you fist..
as we know, previously zend_qsort is not a stable sorting algo.
my draft patch (which already get 0.1% IRs reduce in wordpress)
is kindof a stable sorting algo, you can find it here
(https://github.com/laruence/php-src/compare/zend_sort)
so, there is a bc break, like for :
$array = array("o", "O");
sort($array, SORT_STRING|SORT_FLAG_CASE);
var_dump($array);
previously implementation does the swap:
array(2) {
[0]=>
string(1) "O"
[1]=>
string(1) "o"
}
but new implementation doesn't not:
array(2) {
[0]=>
string(1) "o"
[1]=>
string(1) "O"
}
do you think such BC break is acceptable? or I still need a RFC? :<
thanks
Xinchen Hui
@Laruence
http://www.laruence.com/
Hey:
I was working on zend_qsort improvement. but I got a problem need
to be disscussed with you fist..
firstas we know, previously zend_qsort is not a stable sorting algo. my draft patch (which already get 0.1% IRs reduce in wordpress)
is kindof a stable sorting algo, you can find it here
(https://github.com/laruence/php-src/compare/zend_sort)so, there is a bc break, like for : $array = array("o", "O"); sort($array, SORT_STRING|SORT_FLAG_CASE); var_dump($array); previously implementation does the swap:
array(2) {
[0]=>
string(1) "O"
[1]=>
string(1) "o"
}but new implementation doesn't not:
does not
array(2) {
[0]=>
string(1) "o"
[1]=>
string(1) "O"
}do you think such BC break is acceptable? or I still need a RFC? :<
thanks
Xinchen Hui
@Laruence
http://www.laruence.com/
--
Xinchen Hui
@Laruence
http://www.laruence.com/
Hey:
I was working on zend_qsort improvement. but I got a problem need
to be disscussed with you fist..
firstas we know, previously zend_qsort is not a stable sorting algo. my draft patch (which already get 0.1% IRs reduce in wordpress)
is kindof a stable sorting algo, you can find it here
(https://github.com/laruence/php-src/compare/zend_sort)so, there is a bc break, like for : $array = array("o", "O"); sort($array, SORT_STRING|SORT_FLAG_CASE); var_dump($array); previously implementation does the swap:
array(2) {
[0]=>
string(1) "O"
[1]=>
string(1) "o"
}but new implementation doesn't not:
does not
array(2) {
[0]=>
string(1) "o"
[1]=>
string(1) "O"}
Hum, I dont think such a BC is acceptable.
There are tons of userland code out there relying on alpha case sorting
that could get impacted....
IMO :-)
Q: why extract the swap function from the qsort algo ? Is there an interest
of replacing it at runtime ?
Julien.P
Hey:
Hey:
I was working on zend_qsort improvement. but I got a problem need
to be disscussed with you fist..
firstas we know, previously zend_qsort is not a stable sorting algo. my draft patch (which already get 0.1% IRs reduce in wordpress)
is kindof a stable sorting algo, you can find it here
(https://github.com/laruence/php-src/compare/zend_sort)so, there is a bc break, like for : $array = array("o", "O"); sort($array, SORT_STRING|SORT_FLAG_CASE); var_dump($array); previously implementation does the swap:
array(2) {
[0]=>
string(1) "O"
[1]=>
string(1) "o"
}but new implementation doesn't not:
does not
array(2) {
[0]=>
string(1) "o"
[1]=>
string(1) "O"
}Hum, I dont think such a BC is acceptable.
I am not sure if you get the problem?
"O" and "o" are equal is that script
The flags means using case-insensitive string sorting mean
Thanks
There are tons of userland code out there relying on alpha case sorting that could get impacted....
IMO :-)Q: why extract the swap function from the qsort algo ? Is there an interest of replacing it at runtime ?
Julien.P
Sounds more like a bugfix to me and def'ly an acceptable BC break in
either case. The behavior isn't specified and if anything I would
assume there wouldn't be a swap with SORT_FLAG_CASE
on. Interesting
though that many sorting examples (across languages) sidestep this
clearly common case.
-- S.
Hey:
Hey:
I was working on zend_qsort improvement. but I got a problem need
to be disscussed with you fist..
firstas we know, previously zend_qsort is not a stable sorting algo. my draft patch (which already get 0.1% IRs reduce in wordpress)
is kindof a stable sorting algo, you can find it here
(https://github.com/laruence/php-src/compare/zend_sort)so, there is a bc break, like for : $array = array("o", "O"); sort($array, SORT_STRING|SORT_FLAG_CASE); var_dump($array); previously implementation does the swap:
array(2) {
[0]=>
string(1) "O"
[1]=>
string(1) "o"
}but new implementation doesn't not:
does not
array(2) {
[0]=>
string(1) "o"
[1]=>
string(1) "O"
}Hum, I dont think such a BC is acceptable.
I am not sure if you get the problem?
"O" and "o" are equal is that script
The flags means using case-insensitive string sorting mean
Thanks
There are tons of userland code out there relying on alpha case sorting that could get impacted....
IMO :-)Q: why extract the swap function from the qsort algo ? Is there an interest of replacing it at runtime ?
Julien.P
> do you think such BC break is acceptable? or I still need a RFC? :<
>
Chiming in as a pure userland developer. The documentation already states:
> Note: Like most PHP sorting functions, `sort()` uses an implementation
of » Quicksort. The pivot is chosen in the middle of the partition
resulting in an optimal time for already sorted arrays. This is however
an implementation detail you shouldn't rely on.
As the selection of the pivot element may also affect the order of equal
elements and is explicitly defined as “one should not rely on it” this
change seems to be fine from my perspective.
Tim
>
>> do you think such BC break is acceptable? or I still need a RFC? :<
>>
>
> Chiming in as a pure userland developer. The documentation already states:
>
>> Note: Like most PHP sorting functions, `sort()` uses an implementation
> of » Quicksort. The pivot is chosen in the middle of the partition
> resulting in an optimal time for already sorted arrays. This is however
> an implementation detail you shouldn't rely on.
thanks, then I think no problem.
the reason why I asked is I found lots of test scripts starts to fail,
they all rely on the current non-stable sorting algo :<
thanks
>
> As the selection of the pivot element may also affect the order of equal
> elements and is explicitly defined as “one should not rely on it” this
> change seems to be fine from my perspective.
>
> Tim
--
Xinchen Hui
@Laruence
http://www.laruence.com/
>
>>
>>> do you think such BC break is acceptable? or I still need a RFC? :<
>>>
>>
>> Chiming in as a pure userland developer. The documentation already states:
>>
>>> Note: Like most PHP sorting functions, `sort()` uses an implementation
>> of » Quicksort. The pivot is chosen in the middle of the partition
>> resulting in an optimal time for already sorted arrays. This is however
>> an implementation detail you shouldn't rely on.
> thanks, then I think no problem.
>
> the reason why I asked is I found lots of test scripts starts to fail,
> they all rely on the current non-stable sorting algo :<
We make no promises about the implementation on any of the relevant
documentation pages, besides that it's a quick sort, and we explicitly
say that you can't rely on that. I think we can change this without a
real BC concern (although it would still be worth noting in UPGRADING
and, by extension, the migration guide).
Adam
This sounds reasonable, because given how the sort is not stable, there will be other cases (totally made up, but let's say ["a", "o", "O"]) where the swap does not happen. Consistency, and thus a stable sort, is better.
But you're saying your patch is "kind of a" stable sorting algo, so is it stable only sometimes, or did you mean to say "a kind of"?
David
Hey:
I was working on zend_qsort improvement. but I got a problem need
to be disscussed with you fist..
as we know, previously zend_qsort is not a stable sorting algo. my draft patch (which already get 0.1% IRs reduce in wordpress)
is kindof a stable sorting algo, you can find it here
(https://github.com/laruence/php-src/compare/zend_sort)so, there is a bc break, like for : $array = array("o", "O"); sort($array, SORT_STRING|SORT_FLAG_CASE); var_dump($array); previously implementation does the swap:
array(2) {
[0]=>
string(1) "O"
[1]=>
string(1) "o"
}but new implementation doesn't not:
array(2) {
[0]=>
string(1) "o"
[1]=>
string(1) "O"
}do you think such BC break is acceptable? or I still need a RFC? :<
thanks
Xinchen Hui
@Laruence
http://www.laruence.com/
This sounds reasonable, because given how the sort is not stable, there will be other cases (totally made up, but let's say ["a", "o", "O"]) where the swap does not happen. Consistency, and thus a stable sort, is better.
yeah, I also think in the same way..
But you're saying your patch is "kind of a" stable sorting algo, so is it stable only sometimes, or did you mean to say "a kind of"?
actually, I use insert sort if elements is less than 17(<=16). so...
thanks
David
Hey:
I was working on zend_qsort improvement. but I got a problem need
to be disscussed with you fist..
as we know, previously zend_qsort is not a stable sorting algo. my draft patch (which already get 0.1% IRs reduce in wordpress)
is kindof a stable sorting algo, you can find it here
(https://github.com/laruence/php-src/compare/zend_sort)so, there is a bc break, like for : $array = array("o", "O"); sort($array, SORT_STRING|SORT_FLAG_CASE); var_dump($array); previously implementation does the swap:
array(2) {
[0]=>
string(1) "O"
[1]=>
string(1) "o"
}but new implementation doesn't not:
array(2) {
[0]=>
string(1) "o"
[1]=>
string(1) "O"
}do you think such BC break is acceptable? or I still need a RFC? :<
thanks
Xinchen Hui
@Laruence
http://www.laruence.com/--
--
Xinchen Hui
@Laruence
http://www.laruence.com/
This sounds reasonable, because given how the sort is not stable, there will be other cases (totally made up, but let's say ["a", "o", "O"]) where the swap does not happen. Consistency, and thus a stable sort, is better.
But you're saying your patch is "kind of a" stable sorting algo, so is it stable only sometimes, or did you mean to say "a kind of"?
Afaict, it means "less unstable" but still not stable. Still nice work
and improvement :)
alias by accident and apparently the sender confirmation does not work
properly.
> do you think such BC break is acceptable? or I still need a RFC?
>
Chiming in as a pure userland developer. The documentation already states:
> Note: Like most PHP sorting functions, `sort()` uses an implementation
of » Quicksort. The pivot is chosen in the middle of the partition
resulting in an optimal time for already sorted arrays. This is however
an implementation detail you shouldn't rely on.
As the selection of the pivot element may also affect the order of equal
elements and is explicitly defined as “one should not rely on it” this
change seems to be fine from my perspective.
Tim
hi :)
Hey:
I was working on zend_qsort improvement. but I got a problem need
to be disscussed with you fist..
as we know, previously zend_qsort is not a stable sorting algo. my draft patch (which already get 0.1% IRs reduce in wordpress)
is kindof a stable sorting algo, you can find it here
(https://github.com/laruence/php-src/compare/zend_sort)so, there is a bc break, like for : $array = array("o", "O"); sort($array, SORT_STRING|SORT_FLAG_CASE); var_dump($array); previously implementation does the swap:
array(2) {
[0]=>
string(1) "O"
[1]=>
string(1) "o"
}but new implementation doesn't not:
array(2) {
[0]=>
string(1) "o"
[1]=>
string(1) "O"
}do you think such BC break is acceptable? or I still need a RFC? :<
I am not sure about that. Introducing a not easy to catch BC break for
0.1% gain on function (or even for the whole app) is not very
appealing.
However, there is nothing in the documentation actually describing how
it works and there are clear warnings about the unpredictable results.
That means we won't actually break it,per definition. I only wonder if
it is worth the effort for such little gain (yes, the ocean is made of
drops ;).
Cheers,
Pierre
@pierrejoye | http://www.libgd.org
I am not sure about that. Introducing a not easy to catch BC break for
0.1% gain on function (or even for the whole app) is not very
appealing.However, there is nothing in the documentation actually describing how
it works and there are clear warnings about the unpredictable results.
That means we won't actually break it,per definition. I only wonder if
it is worth the effort for such little gain (yes, the ocean is made of
drops ;).
The clear benefit I see is that it turns it into a stable sort, although we could of course always break that again in the future unless we explicitly specify/guarantee it to be stable from now on (without any other guarantees about the algorithm).
Hi all,
I am not sure about that. Introducing a not easy to catch BC break for
0.1% gain on function (or even for the whole app) is not very
appealing.However, there is nothing in the documentation actually describing how
it works and there are clear warnings about the unpredictable results.
That means we won't actually break it,per definition. I only wonder if
it is worth the effort for such little gain (yes, the ocean is made of
drops ;).The clear benefit I see is that it turns it into a stable sort, although
we could of course always break that again in the future unless we
explicitly specify/guarantee it to be stable from now on (without any other
guarantees about the algorithm).
Stable sort is more intuitive than unstable sort.
Since stable sort is a little faster than current, the only issue would be
"whether we will make it a feature or not".
This might be a good theme for RFC in the future.
(Just merge the patch and decide later.)
Regards,
--
Yasuo Ohgaki
yohgaki@ohgaki.net
I think this break is acceptable
Of course, if the new sort implementation significantly improves
performance on some cases and doesn't show degradation on the others.
Thanks. Dmitry.
Hey:
I was working on zend_qsort improvement. but I got a problem need
to be disscussed with you fist..
as we know, previously zend_qsort is not a stable sorting algo. my draft patch (which already get 0.1% IRs reduce in wordpress)
is kindof a stable sorting algo, you can find it here
(https://github.com/laruence/php-src/compare/zend_sort)so, there is a bc break, like for : $array = array("o", "O"); sort($array, SORT_STRING|SORT_FLAG_CASE); var_dump($array); previously implementation does the swap:
array(2) {
[0]=>
string(1) "O"
[1]=>
string(1) "o"
}but new implementation doesn't not:
array(2) {
[0]=>
string(1) "o"
[1]=>
string(1) "O"
}do you think such BC break is acceptable? or I still need a RFC? :<
thanks
Xinchen Hui
@Laruence
http://www.laruence.com/
Hey:
I made a PR here: https://github.com/php/php-src/pull/999 for reviewing
in benchmark this can brings more than 30% performance gain in
array_sort etc functions.
tests fails are related to non-stable vs stable sorting difference.
anyway, I feel it's better to ask you to do a final review, what
do you think?
is there any objections to merge this?
thanks
Hey:
I was working on zend_qsort improvement. but I got a problem need
to be disscussed with you fist..
as we know, previously zend_qsort is not a stable sorting algo. my draft patch (which already get 0.1% IRs reduce in wordpress)
is kindof a stable sorting algo, you can find it here
(https://github.com/laruence/php-src/compare/zend_sort)so, there is a bc break, like for : $array = array("o", "O"); sort($array, SORT_STRING|SORT_FLAG_CASE); var_dump($array); previously implementation does the swap:
array(2) {
[0]=>
string(1) "O"
[1]=>
string(1) "o"
}but new implementation doesn't not:
array(2) {
[0]=>
string(1) "o"
[1]=>
string(1) "O"
}do you think such BC break is acceptable? or I still need a RFC? :<
thanks
Xinchen Hui
@Laruence
http://www.laruence.com/
--
Xinchen Hui
@Laruence
http://www.laruence.com/
I don't see big problems committing this.
In some cases new sort()
functions may provide different results, but they
are still valid, because the order of "equal" elements after sort is not
defined.
Thanks. Dmitry.
Hey:
I made a PR here: https://github.com/php/php-src/pull/999 for
reviewing
in benchmark this can brings more than 30% performance gain in
array_sort etc functions.
tests fails are related to non-stable vs stable sorting difference. anyway, I feel it's better to ask you to do a final review, what
do you think?
is there any objections to merge this?
thanks
Hey:
I was working on zend_qsort improvement. but I got a problem need
to be disscussed with you fist..
as we know, previously zend_qsort is not a stable sorting algo. my draft patch (which already get 0.1% IRs reduce in wordpress)
is kindof a stable sorting algo, you can find it here
(https://github.com/laruence/php-src/compare/zend_sort)so, there is a bc break, like for : $array = array("o", "O"); sort($array, SORT_STRING|SORT_FLAG_CASE); var_dump($array); previously implementation does the swap:
array(2) {
[0]=>
string(1) "O"
[1]=>
string(1) "o"
}but new implementation doesn't not:
array(2) {
[0]=>
string(1) "o"
[1]=>
string(1) "O"
}do you think such BC break is acceptable? or I still need a RFC? :<
thanks
Xinchen Hui
@Laruence
http://www.laruence.com/--
Xinchen Hui
@Laruence
http://www.laruence.com/
Hi!
I made a PR here: https://github.com/php/php-src/pull/999 for reviewing in benchmark this can brings more than 30% performance gain in
array_sort etc functions.
tests fails are related to non-stable vs stable sorting difference. anyway, I feel it's better to ask you to do a final review, what
do you think?
is there any objections to merge this?
I think the sort order of equal elements was never defined, so changing
it would not be a big issue. The tests, of course, need to be fixed and
note in UPGRADING should be provided, but otherwise it's fine.
--
Stas Malyshev
smalyshev@gmail.com
Hi!
I made a PR here: https://github.com/php/php-src/pull/999 for reviewing in benchmark this can brings more than 30% performance gain in
array_sort etc functions.
tests fails are related to non-stable vs stable sorting difference. anyway, I feel it's better to ask you to do a final review, what
do you think?
is there any objections to merge this?
I think the sort order of equal elements was never defined, so changing
it would not be a big issue. The tests, of course, need to be fixed and
note in UPGRADING should be provided, but otherwise it's fine.
Same here, all good as long as a notice is present and tests are updated.
Hey:
Hi!
I made a PR here: https://github.com/php/php-src/pull/999 for reviewing in benchmark this can brings more than 30% performance gain in
array_sort etc functions.
tests fails are related to non-stable vs stable sorting difference. anyway, I feel it's better to ask you to do a final review, what
do you think?
is there any objections to merge this?
I think the sort order of equal elements was never defined, so changing
it would not be a big issue. The tests, of course, need to be fixed and
note in UPGRADING should be provided, but otherwise it's fine.Same here, all good as long as a notice is present and tests are updated.
thanks for the reviewing,
I am going to merge it.
I have got some ideas to improve based on this patch.. so I'd like to
merge it first.
thanks
--
Xinchen Hui
@Laruence
http://www.laruence.com/
Hi Xinchen,
my draft patch (which already get 0.1% IRs reduce in wordpress)
could you or anyone else help me understand what IR stands for?
Thanks in advance.
We measure them using callgrind to analyze micro-improvements.
See https://wiki.php.net/phpng#performance_evaluation for more details.
Thanks. Dmitry.
> Hi Xinchen,
>
>> my draft patch (which already get 0.1% IRs reduce in wordpress)
>>
>
> could you or anyone else help me understand what IR stands for?
>
> Thanks in advance.