Is there ever a reason not to use Java 8's parallelSort?Difference between Arrays.sort() and Arrays.parallelSort()Is Java “pass-by-reference” or “pass-by-value”?How do I efficiently iterate over each entry in a Java Map?Does a finally block always get executed in Java?What is the difference between public, protected, package-private and private in Java?How do I read / convert an InputStream into a String in Java?When to use LinkedList over ArrayList in Java?How do I generate random integers within a specific range in Java?How do I determine whether an array contains a particular value in Java?How do I convert a String to an int in Java?Creating a memory leak with Java
Isn't "Dave's protocol" good if only the database, and not the code, is leaked?
How to create a 2D table with varying step?
Is my background sufficient to start Quantum Computing
Is it possible to spoof an IP address to an exact number?
Can Monks cast spells?
What is the difference between a historical drama and a period drama?
What is a "tittering order"?
Blood-based alcohol for vampires?
Construction of the word подтвержда́ть
How is /a/ pronounced before n/m in French?
"Best practices" for formulating MIPs
Performance of loop vs expansion
What could a Medieval society do with excess animal blood?
Where is read command?
Show that there are infinitely more problems than we will ever be able to compute
Is there any connection between "Whispers of the heart" and "The cat returns"?
Phrasing "it says" or "it reads"
Is there ever a reason not to use Java 8's parallelSort?
Is it possible that Curiosity measured its own methane or failed doing the spectrometry?
Olive oil in Japanese cooking
What do you call the angle of the direction of an airplane?
Why did my leaking pool light trip the circuit breaker, but not the GFCI?
Auto replacement of characters
Why did moving the mouse cursor cause Windows 95 to run more quickly?
Is there ever a reason not to use Java 8's parallelSort?
Difference between Arrays.sort() and Arrays.parallelSort()Is Java “pass-by-reference” or “pass-by-value”?How do I efficiently iterate over each entry in a Java Map?Does a finally block always get executed in Java?What is the difference between public, protected, package-private and private in Java?How do I read / convert an InputStream into a String in Java?When to use LinkedList over ArrayList in Java?How do I generate random integers within a specific range in Java?How do I determine whether an array contains a particular value in Java?How do I convert a String to an int in Java?Creating a memory leak with Java
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I was reading this question about the differences between Java's Arrays.sort
and Arrays.parallelSort
, which is a few years old by now. What surprised me is that there was only one question that mentioned any downside to using parallelSort
; namely that the speedup decreases if you're using a lot of your CPU.
Assuming you're not in some sort of specialized, single-threaded environment, should one always choose parallelSort
? Is there ever a reason not to? Note that one of the answers to the question above mentions that if there are fewer than 4096 elements, parallelSort
simply calls sort
anyway.
java sorting parallel-processing
add a comment |
I was reading this question about the differences between Java's Arrays.sort
and Arrays.parallelSort
, which is a few years old by now. What surprised me is that there was only one question that mentioned any downside to using parallelSort
; namely that the speedup decreases if you're using a lot of your CPU.
Assuming you're not in some sort of specialized, single-threaded environment, should one always choose parallelSort
? Is there ever a reason not to? Note that one of the answers to the question above mentions that if there are fewer than 4096 elements, parallelSort
simply calls sort
anyway.
java sorting parallel-processing
It might be a problem when running in a Java EE container.
– JF Meier
8 hours ago
1
@JFMeier no,Arrays.parallelSort
explicitly checks if the common pool has only one thread and thus won't perform worse (compared to the non-parallel sort) with only 1 thread in the common pool, see here for example. But yes, the common pool has very little / 1 thread(s) in a servlet context, which may be a pitfall
– roookeee
8 hours ago
add a comment |
I was reading this question about the differences between Java's Arrays.sort
and Arrays.parallelSort
, which is a few years old by now. What surprised me is that there was only one question that mentioned any downside to using parallelSort
; namely that the speedup decreases if you're using a lot of your CPU.
Assuming you're not in some sort of specialized, single-threaded environment, should one always choose parallelSort
? Is there ever a reason not to? Note that one of the answers to the question above mentions that if there are fewer than 4096 elements, parallelSort
simply calls sort
anyway.
java sorting parallel-processing
I was reading this question about the differences between Java's Arrays.sort
and Arrays.parallelSort
, which is a few years old by now. What surprised me is that there was only one question that mentioned any downside to using parallelSort
; namely that the speedup decreases if you're using a lot of your CPU.
Assuming you're not in some sort of specialized, single-threaded environment, should one always choose parallelSort
? Is there ever a reason not to? Note that one of the answers to the question above mentions that if there are fewer than 4096 elements, parallelSort
simply calls sort
anyway.
java sorting parallel-processing
java sorting parallel-processing
edited 8 hours ago
John Kugelman
256k56 gold badges416 silver badges467 bronze badges
256k56 gold badges416 silver badges467 bronze badges
asked 8 hours ago
Calvin GodfreyCalvin Godfrey
9932 silver badges15 bronze badges
9932 silver badges15 bronze badges
It might be a problem when running in a Java EE container.
– JF Meier
8 hours ago
1
@JFMeier no,Arrays.parallelSort
explicitly checks if the common pool has only one thread and thus won't perform worse (compared to the non-parallel sort) with only 1 thread in the common pool, see here for example. But yes, the common pool has very little / 1 thread(s) in a servlet context, which may be a pitfall
– roookeee
8 hours ago
add a comment |
It might be a problem when running in a Java EE container.
– JF Meier
8 hours ago
1
@JFMeier no,Arrays.parallelSort
explicitly checks if the common pool has only one thread and thus won't perform worse (compared to the non-parallel sort) with only 1 thread in the common pool, see here for example. But yes, the common pool has very little / 1 thread(s) in a servlet context, which may be a pitfall
– roookeee
8 hours ago
It might be a problem when running in a Java EE container.
– JF Meier
8 hours ago
It might be a problem when running in a Java EE container.
– JF Meier
8 hours ago
1
1
@JFMeier no,
Arrays.parallelSort
explicitly checks if the common pool has only one thread and thus won't perform worse (compared to the non-parallel sort) with only 1 thread in the common pool, see here for example. But yes, the common pool has very little / 1 thread(s) in a servlet context, which may be a pitfall– roookeee
8 hours ago
@JFMeier no,
Arrays.parallelSort
explicitly checks if the common pool has only one thread and thus won't perform worse (compared to the non-parallel sort) with only 1 thread in the common pool, see here for example. But yes, the common pool has very little / 1 thread(s) in a servlet context, which may be a pitfall– roookeee
8 hours ago
add a comment |
2 Answers
2
active
oldest
votes
There are some downsides to using Arrays.parallelSort
- it uses the
ForkJoinPool.commonPool()
and will fight with other functions that use it by default (e.g.parallel()
on a stream) - the thread-pool
Arrays.parallelSort
uses is not configurable (only on a global level by increasing the common-pools thread amount) - it performs worse on small data sets (more often than not arrays contain little elements, the JDK even acknowledges that e.g. most
ArrayList
stay empty for their whole lifetime which saves quite a bit of memory and CPU time for not instantiating arrays that will never be filled)
And another anecdotal scenario: say if you implement some card game that needs sorting. Its embarassingly easy to parallelize multiple game executions next to each other instead of parallelizing the sorting mechanism of one run which may only take a fraction of the whole game loop. You lost an easy way to parallelize now.
But yes, if you happen to have large arrays and sorting is a substantial part of your applications runtime use Arrays.parallelSort
.
EDIT:
And even if Arrays.parallelSort
switches to a normal sort if the given array has less than 4096 elements: it's all about showing intention - you want a parallel sort if possible which holds a different meaning than just calling sort
. And to be nitpicky: it does indeed perform worse on small arrays as it has to do the additional check if the array is containing less than 4096 elements and some other checks about the common pools thread count (whichs overhead is of course negligible) :).
add a comment |
No, I would say no for small enough arrays. The overhead of setting up the threads won't result in an observable speed up.
The key is "small enough". It won't be the same answer for all problems.
Dogma should never be applied, except in the case of this dogma rule. Just like the only thing we should never tolerate is intolerance. There's a Popper paradox in there somewhere.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f56841334%2fis-there-ever-a-reason-not-to-use-java-8s-parallelsort%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
There are some downsides to using Arrays.parallelSort
- it uses the
ForkJoinPool.commonPool()
and will fight with other functions that use it by default (e.g.parallel()
on a stream) - the thread-pool
Arrays.parallelSort
uses is not configurable (only on a global level by increasing the common-pools thread amount) - it performs worse on small data sets (more often than not arrays contain little elements, the JDK even acknowledges that e.g. most
ArrayList
stay empty for their whole lifetime which saves quite a bit of memory and CPU time for not instantiating arrays that will never be filled)
And another anecdotal scenario: say if you implement some card game that needs sorting. Its embarassingly easy to parallelize multiple game executions next to each other instead of parallelizing the sorting mechanism of one run which may only take a fraction of the whole game loop. You lost an easy way to parallelize now.
But yes, if you happen to have large arrays and sorting is a substantial part of your applications runtime use Arrays.parallelSort
.
EDIT:
And even if Arrays.parallelSort
switches to a normal sort if the given array has less than 4096 elements: it's all about showing intention - you want a parallel sort if possible which holds a different meaning than just calling sort
. And to be nitpicky: it does indeed perform worse on small arrays as it has to do the additional check if the array is containing less than 4096 elements and some other checks about the common pools thread count (whichs overhead is of course negligible) :).
add a comment |
There are some downsides to using Arrays.parallelSort
- it uses the
ForkJoinPool.commonPool()
and will fight with other functions that use it by default (e.g.parallel()
on a stream) - the thread-pool
Arrays.parallelSort
uses is not configurable (only on a global level by increasing the common-pools thread amount) - it performs worse on small data sets (more often than not arrays contain little elements, the JDK even acknowledges that e.g. most
ArrayList
stay empty for their whole lifetime which saves quite a bit of memory and CPU time for not instantiating arrays that will never be filled)
And another anecdotal scenario: say if you implement some card game that needs sorting. Its embarassingly easy to parallelize multiple game executions next to each other instead of parallelizing the sorting mechanism of one run which may only take a fraction of the whole game loop. You lost an easy way to parallelize now.
But yes, if you happen to have large arrays and sorting is a substantial part of your applications runtime use Arrays.parallelSort
.
EDIT:
And even if Arrays.parallelSort
switches to a normal sort if the given array has less than 4096 elements: it's all about showing intention - you want a parallel sort if possible which holds a different meaning than just calling sort
. And to be nitpicky: it does indeed perform worse on small arrays as it has to do the additional check if the array is containing less than 4096 elements and some other checks about the common pools thread count (whichs overhead is of course negligible) :).
add a comment |
There are some downsides to using Arrays.parallelSort
- it uses the
ForkJoinPool.commonPool()
and will fight with other functions that use it by default (e.g.parallel()
on a stream) - the thread-pool
Arrays.parallelSort
uses is not configurable (only on a global level by increasing the common-pools thread amount) - it performs worse on small data sets (more often than not arrays contain little elements, the JDK even acknowledges that e.g. most
ArrayList
stay empty for their whole lifetime which saves quite a bit of memory and CPU time for not instantiating arrays that will never be filled)
And another anecdotal scenario: say if you implement some card game that needs sorting. Its embarassingly easy to parallelize multiple game executions next to each other instead of parallelizing the sorting mechanism of one run which may only take a fraction of the whole game loop. You lost an easy way to parallelize now.
But yes, if you happen to have large arrays and sorting is a substantial part of your applications runtime use Arrays.parallelSort
.
EDIT:
And even if Arrays.parallelSort
switches to a normal sort if the given array has less than 4096 elements: it's all about showing intention - you want a parallel sort if possible which holds a different meaning than just calling sort
. And to be nitpicky: it does indeed perform worse on small arrays as it has to do the additional check if the array is containing less than 4096 elements and some other checks about the common pools thread count (whichs overhead is of course negligible) :).
There are some downsides to using Arrays.parallelSort
- it uses the
ForkJoinPool.commonPool()
and will fight with other functions that use it by default (e.g.parallel()
on a stream) - the thread-pool
Arrays.parallelSort
uses is not configurable (only on a global level by increasing the common-pools thread amount) - it performs worse on small data sets (more often than not arrays contain little elements, the JDK even acknowledges that e.g. most
ArrayList
stay empty for their whole lifetime which saves quite a bit of memory and CPU time for not instantiating arrays that will never be filled)
And another anecdotal scenario: say if you implement some card game that needs sorting. Its embarassingly easy to parallelize multiple game executions next to each other instead of parallelizing the sorting mechanism of one run which may only take a fraction of the whole game loop. You lost an easy way to parallelize now.
But yes, if you happen to have large arrays and sorting is a substantial part of your applications runtime use Arrays.parallelSort
.
EDIT:
And even if Arrays.parallelSort
switches to a normal sort if the given array has less than 4096 elements: it's all about showing intention - you want a parallel sort if possible which holds a different meaning than just calling sort
. And to be nitpicky: it does indeed perform worse on small arrays as it has to do the additional check if the array is containing less than 4096 elements and some other checks about the common pools thread count (whichs overhead is of course negligible) :).
edited 7 hours ago
answered 8 hours ago
roookeeeroookeee
7103 silver badges12 bronze badges
7103 silver badges12 bronze badges
add a comment |
add a comment |
No, I would say no for small enough arrays. The overhead of setting up the threads won't result in an observable speed up.
The key is "small enough". It won't be the same answer for all problems.
Dogma should never be applied, except in the case of this dogma rule. Just like the only thing we should never tolerate is intolerance. There's a Popper paradox in there somewhere.
add a comment |
No, I would say no for small enough arrays. The overhead of setting up the threads won't result in an observable speed up.
The key is "small enough". It won't be the same answer for all problems.
Dogma should never be applied, except in the case of this dogma rule. Just like the only thing we should never tolerate is intolerance. There's a Popper paradox in there somewhere.
add a comment |
No, I would say no for small enough arrays. The overhead of setting up the threads won't result in an observable speed up.
The key is "small enough". It won't be the same answer for all problems.
Dogma should never be applied, except in the case of this dogma rule. Just like the only thing we should never tolerate is intolerance. There's a Popper paradox in there somewhere.
No, I would say no for small enough arrays. The overhead of setting up the threads won't result in an observable speed up.
The key is "small enough". It won't be the same answer for all problems.
Dogma should never be applied, except in the case of this dogma rule. Just like the only thing we should never tolerate is intolerance. There's a Popper paradox in there somewhere.
answered 8 hours ago
duffymoduffymo
275k38 gold badges325 silver badges514 bronze badges
275k38 gold badges325 silver badges514 bronze badges
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f56841334%2fis-there-ever-a-reason-not-to-use-java-8s-parallelsort%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
It might be a problem when running in a Java EE container.
– JF Meier
8 hours ago
1
@JFMeier no,
Arrays.parallelSort
explicitly checks if the common pool has only one thread and thus won't perform worse (compared to the non-parallel sort) with only 1 thread in the common pool, see here for example. But yes, the common pool has very little / 1 thread(s) in a servlet context, which may be a pitfall– roookeee
8 hours ago