You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by "Sergey Dmitriev (JIRA)" <ji...@apache.org> on 2007/10/25 20:26:51 UTC
[jira] Created: (HARMONY-5025) [classlib][nio] make
AbstractSelectableChannel.containsValidKeys() a little bit faster
[classlib][nio] make AbstractSelectableChannel.containsValidKeys() a little bit faster
--------------------------------------------------------------------------------------
Key: HARMONY-5025
URL: https://issues.apache.org/jira/browse/HARMONY-5025
Project: Harmony
Issue Type: Improvement
Components: Classlib
Reporter: Sergey Dmitriev
Some time ago I've found a piece of code in NIO which can be simply improved.
AbstractSelectableChannel.java:
/**
* Returns true if the keyList contains at least 1 valid key and false otherwise.
*/
private synchronized boolean containsValidKeys() {
- for (Iterator<SelectionKey> iter = keyList.iterator(); iter.hasNext();) {
- SelectionKey key = iter.next();
+ for (int i=0; i<keyList.size(); i++) {
+ SelectionKey key = keyList.get(i);
if (key != null && key.isValid()) {
return true;
}
}
}
Just don't create an Iterator here. Indeed no big deal, but it would be just pity to loose this discovery. :)
I even created the mini test to demonstrate the benefit of my patch (approx 10%).
{guy@nowhere:~/tmp} cat cvk.java
import java.io.*;
import java.nio.channels.*;
// cvk: containsValidKeys()
public class cvk {
static int numOfIters = 10;
static int numOfConfigures = 10*1000*1000;
public static void main(String[] args) throws Exception {
ServerSocketChannel ssc = ServerSocketChannel.open();
for (int i=0; i<numOfIters; i++) {
long millis = System.currentTimeMillis();
for (int j=0; j<numOfConfigures; j++) {
ssc.configureBlocking(false);
ssc.configureBlocking(true);
}
System.out.println(System.currentTimeMillis() - millis);
}
}
}
{guy@nowhere:~/tmp} ~/harmony.29sep.my.nocvk/bin/java -Xem:server cvk
7049
6149
6134
6125
6140
6139
6131
6142
6148
6200
{guy@nowhere:~/tmp} ~/harmony.29sep.my.cvk/bin/java -Xem:server cvk
5769
5499
5491
5497
5483
5474
5466
5470
5453
5478
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Closed: (HARMONY-5025) [classlib][nio] make
AbstractSelectableChannel.containsValidKeys() a little bit faster
Posted by "Tim Ellison (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/HARMONY-5025?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Tim Ellison closed HARMONY-5025.
--------------------------------
Verified by Sergey.
> [classlib][nio] make AbstractSelectableChannel.containsValidKeys() a little bit faster
> --------------------------------------------------------------------------------------
>
> Key: HARMONY-5025
> URL: https://issues.apache.org/jira/browse/HARMONY-5025
> Project: Harmony
> Issue Type: Improvement
> Components: Classlib
> Reporter: Sergey Dmitriev
> Assignee: Tim Ellison
> Attachments: cvk.patch
>
>
> Some time ago I've found a piece of code in NIO which can be simply improved.
> AbstractSelectableChannel.java:
> /**
> * Returns true if the keyList contains at least 1 valid key and false otherwise.
> */
> private synchronized boolean containsValidKeys() {
> - for (Iterator<SelectionKey> iter = keyList.iterator(); iter.hasNext();) {
> - SelectionKey key = iter.next();
> + for (int i=0; i<keyList.size(); i++) {
> + SelectionKey key = keyList.get(i);
> if (key != null && key.isValid()) {
> return true;
> }
> }
> }
> Just don't create an Iterator here. Indeed no big deal, but it would be just pity to loose this discovery. :)
> I even created the mini test to demonstrate the benefit of my patch (approx 10%).
> {guy@nowhere:~/tmp} cat cvk.java
> import java.io.*;
> import java.nio.channels.*;
> // cvk: containsValidKeys()
> public class cvk {
> static int numOfIters = 10;
> static int numOfConfigures = 10*1000*1000;
> public static void main(String[] args) throws Exception {
> ServerSocketChannel ssc = ServerSocketChannel.open();
> for (int i=0; i<numOfIters; i++) {
> long millis = System.currentTimeMillis();
> for (int j=0; j<numOfConfigures; j++) {
> ssc.configureBlocking(false);
> ssc.configureBlocking(true);
> }
> System.out.println(System.currentTimeMillis() - millis);
> }
> }
> }
> {guy@nowhere:~/tmp} ~/harmony.29sep.my.nocvk/bin/java -Xem:server cvk
> 7049
> 6149
> 6134
> 6125
> 6140
> 6139
> 6131
> 6142
> 6148
> 6200
> {guy@nowhere:~/tmp} ~/harmony.29sep.my.cvk/bin/java -Xem:server cvk
> 5769
> 5499
> 5491
> 5497
> 5483
> 5474
> 5466
> 5470
> 5453
> 5478
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Updated: (HARMONY-5025) [classlib][nio] make
AbstractSelectableChannel.containsValidKeys() a little bit faster
Posted by "Sergey Dmitriev (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/HARMONY-5025?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Sergey Dmitriev updated HARMONY-5025:
-------------------------------------
Attachment: cvk.patch
> [classlib][nio] make AbstractSelectableChannel.containsValidKeys() a little bit faster
> --------------------------------------------------------------------------------------
>
> Key: HARMONY-5025
> URL: https://issues.apache.org/jira/browse/HARMONY-5025
> Project: Harmony
> Issue Type: Improvement
> Components: Classlib
> Reporter: Sergey Dmitriev
> Attachments: cvk.patch
>
>
> Some time ago I've found a piece of code in NIO which can be simply improved.
> AbstractSelectableChannel.java:
> /**
> * Returns true if the keyList contains at least 1 valid key and false otherwise.
> */
> private synchronized boolean containsValidKeys() {
> - for (Iterator<SelectionKey> iter = keyList.iterator(); iter.hasNext();) {
> - SelectionKey key = iter.next();
> + for (int i=0; i<keyList.size(); i++) {
> + SelectionKey key = keyList.get(i);
> if (key != null && key.isValid()) {
> return true;
> }
> }
> }
> Just don't create an Iterator here. Indeed no big deal, but it would be just pity to loose this discovery. :)
> I even created the mini test to demonstrate the benefit of my patch (approx 10%).
> {guy@nowhere:~/tmp} cat cvk.java
> import java.io.*;
> import java.nio.channels.*;
> // cvk: containsValidKeys()
> public class cvk {
> static int numOfIters = 10;
> static int numOfConfigures = 10*1000*1000;
> public static void main(String[] args) throws Exception {
> ServerSocketChannel ssc = ServerSocketChannel.open();
> for (int i=0; i<numOfIters; i++) {
> long millis = System.currentTimeMillis();
> for (int j=0; j<numOfConfigures; j++) {
> ssc.configureBlocking(false);
> ssc.configureBlocking(true);
> }
> System.out.println(System.currentTimeMillis() - millis);
> }
> }
> }
> {guy@nowhere:~/tmp} ~/harmony.29sep.my.nocvk/bin/java -Xem:server cvk
> 7049
> 6149
> 6134
> 6125
> 6140
> 6139
> 6131
> 6142
> 6148
> 6200
> {guy@nowhere:~/tmp} ~/harmony.29sep.my.cvk/bin/java -Xem:server cvk
> 5769
> 5499
> 5491
> 5497
> 5483
> 5474
> 5466
> 5470
> 5453
> 5478
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Resolved: (HARMONY-5025) [classlib][nio] make
AbstractSelectableChannel.containsValidKeys() a little bit faster
Posted by "Tim Ellison (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/HARMONY-5025?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Tim Ellison resolved HARMONY-5025.
----------------------------------
Resolution: Fixed
Thanks Sergey.
Probably not the most performance critical method call. but hey!, we'll take improvements wherever we can <g>.
Patch applied to NIO module at repo revision r588319.
Please confirm it was applied as you expected.
> [classlib][nio] make AbstractSelectableChannel.containsValidKeys() a little bit faster
> --------------------------------------------------------------------------------------
>
> Key: HARMONY-5025
> URL: https://issues.apache.org/jira/browse/HARMONY-5025
> Project: Harmony
> Issue Type: Improvement
> Components: Classlib
> Reporter: Sergey Dmitriev
> Assignee: Tim Ellison
> Attachments: cvk.patch
>
>
> Some time ago I've found a piece of code in NIO which can be simply improved.
> AbstractSelectableChannel.java:
> /**
> * Returns true if the keyList contains at least 1 valid key and false otherwise.
> */
> private synchronized boolean containsValidKeys() {
> - for (Iterator<SelectionKey> iter = keyList.iterator(); iter.hasNext();) {
> - SelectionKey key = iter.next();
> + for (int i=0; i<keyList.size(); i++) {
> + SelectionKey key = keyList.get(i);
> if (key != null && key.isValid()) {
> return true;
> }
> }
> }
> Just don't create an Iterator here. Indeed no big deal, but it would be just pity to loose this discovery. :)
> I even created the mini test to demonstrate the benefit of my patch (approx 10%).
> {guy@nowhere:~/tmp} cat cvk.java
> import java.io.*;
> import java.nio.channels.*;
> // cvk: containsValidKeys()
> public class cvk {
> static int numOfIters = 10;
> static int numOfConfigures = 10*1000*1000;
> public static void main(String[] args) throws Exception {
> ServerSocketChannel ssc = ServerSocketChannel.open();
> for (int i=0; i<numOfIters; i++) {
> long millis = System.currentTimeMillis();
> for (int j=0; j<numOfConfigures; j++) {
> ssc.configureBlocking(false);
> ssc.configureBlocking(true);
> }
> System.out.println(System.currentTimeMillis() - millis);
> }
> }
> }
> {guy@nowhere:~/tmp} ~/harmony.29sep.my.nocvk/bin/java -Xem:server cvk
> 7049
> 6149
> 6134
> 6125
> 6140
> 6139
> 6131
> 6142
> 6148
> 6200
> {guy@nowhere:~/tmp} ~/harmony.29sep.my.cvk/bin/java -Xem:server cvk
> 5769
> 5499
> 5491
> 5497
> 5483
> 5474
> 5466
> 5470
> 5453
> 5478
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Commented: (HARMONY-5025) [classlib][nio] make
AbstractSelectableChannel.containsValidKeys() a little bit faster
Posted by "Alexey Varlamov (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/HARMONY-5025?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12537833 ]
Alexey Varlamov commented on HARMONY-5025:
------------------------------------------
Heh, then reverse cycle should be a bit more faster ;)
> [classlib][nio] make AbstractSelectableChannel.containsValidKeys() a little bit faster
> --------------------------------------------------------------------------------------
>
> Key: HARMONY-5025
> URL: https://issues.apache.org/jira/browse/HARMONY-5025
> Project: Harmony
> Issue Type: Improvement
> Components: Classlib
> Reporter: Sergey Dmitriev
> Assignee: Tim Ellison
> Attachments: cvk.patch
>
>
> Some time ago I've found a piece of code in NIO which can be simply improved.
> AbstractSelectableChannel.java:
> /**
> * Returns true if the keyList contains at least 1 valid key and false otherwise.
> */
> private synchronized boolean containsValidKeys() {
> - for (Iterator<SelectionKey> iter = keyList.iterator(); iter.hasNext();) {
> - SelectionKey key = iter.next();
> + for (int i=0; i<keyList.size(); i++) {
> + SelectionKey key = keyList.get(i);
> if (key != null && key.isValid()) {
> return true;
> }
> }
> }
> Just don't create an Iterator here. Indeed no big deal, but it would be just pity to loose this discovery. :)
> I even created the mini test to demonstrate the benefit of my patch (approx 10%).
> {guy@nowhere:~/tmp} cat cvk.java
> import java.io.*;
> import java.nio.channels.*;
> // cvk: containsValidKeys()
> public class cvk {
> static int numOfIters = 10;
> static int numOfConfigures = 10*1000*1000;
> public static void main(String[] args) throws Exception {
> ServerSocketChannel ssc = ServerSocketChannel.open();
> for (int i=0; i<numOfIters; i++) {
> long millis = System.currentTimeMillis();
> for (int j=0; j<numOfConfigures; j++) {
> ssc.configureBlocking(false);
> ssc.configureBlocking(true);
> }
> System.out.println(System.currentTimeMillis() - millis);
> }
> }
> }
> {guy@nowhere:~/tmp} ~/harmony.29sep.my.nocvk/bin/java -Xem:server cvk
> 7049
> 6149
> 6134
> 6125
> 6140
> 6139
> 6131
> 6142
> 6148
> 6200
> {guy@nowhere:~/tmp} ~/harmony.29sep.my.cvk/bin/java -Xem:server cvk
> 5769
> 5499
> 5491
> 5497
> 5483
> 5474
> 5466
> 5470
> 5453
> 5478
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Commented: (HARMONY-5025) [classlib][nio] make
AbstractSelectableChannel.containsValidKeys() a little bit faster
Posted by "Sergey Dmitriev (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/HARMONY-5025?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12537894 ]
Sergey Dmitriev commented on HARMONY-5025:
------------------------------------------
Thanks for understanding the point guys! :)
Tim, the patch is applied just fine.
> [classlib][nio] make AbstractSelectableChannel.containsValidKeys() a little bit faster
> --------------------------------------------------------------------------------------
>
> Key: HARMONY-5025
> URL: https://issues.apache.org/jira/browse/HARMONY-5025
> Project: Harmony
> Issue Type: Improvement
> Components: Classlib
> Reporter: Sergey Dmitriev
> Assignee: Tim Ellison
> Attachments: cvk.patch
>
>
> Some time ago I've found a piece of code in NIO which can be simply improved.
> AbstractSelectableChannel.java:
> /**
> * Returns true if the keyList contains at least 1 valid key and false otherwise.
> */
> private synchronized boolean containsValidKeys() {
> - for (Iterator<SelectionKey> iter = keyList.iterator(); iter.hasNext();) {
> - SelectionKey key = iter.next();
> + for (int i=0; i<keyList.size(); i++) {
> + SelectionKey key = keyList.get(i);
> if (key != null && key.isValid()) {
> return true;
> }
> }
> }
> Just don't create an Iterator here. Indeed no big deal, but it would be just pity to loose this discovery. :)
> I even created the mini test to demonstrate the benefit of my patch (approx 10%).
> {guy@nowhere:~/tmp} cat cvk.java
> import java.io.*;
> import java.nio.channels.*;
> // cvk: containsValidKeys()
> public class cvk {
> static int numOfIters = 10;
> static int numOfConfigures = 10*1000*1000;
> public static void main(String[] args) throws Exception {
> ServerSocketChannel ssc = ServerSocketChannel.open();
> for (int i=0; i<numOfIters; i++) {
> long millis = System.currentTimeMillis();
> for (int j=0; j<numOfConfigures; j++) {
> ssc.configureBlocking(false);
> ssc.configureBlocking(true);
> }
> System.out.println(System.currentTimeMillis() - millis);
> }
> }
> }
> {guy@nowhere:~/tmp} ~/harmony.29sep.my.nocvk/bin/java -Xem:server cvk
> 7049
> 6149
> 6134
> 6125
> 6140
> 6139
> 6131
> 6142
> 6148
> 6200
> {guy@nowhere:~/tmp} ~/harmony.29sep.my.cvk/bin/java -Xem:server cvk
> 5769
> 5499
> 5491
> 5497
> 5483
> 5474
> 5466
> 5470
> 5453
> 5478
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Assigned: (HARMONY-5025) [classlib][nio] make
AbstractSelectableChannel.containsValidKeys() a little bit faster
Posted by "Tim Ellison (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/HARMONY-5025?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Tim Ellison reassigned HARMONY-5025:
------------------------------------
Assignee: Tim Ellison
> [classlib][nio] make AbstractSelectableChannel.containsValidKeys() a little bit faster
> --------------------------------------------------------------------------------------
>
> Key: HARMONY-5025
> URL: https://issues.apache.org/jira/browse/HARMONY-5025
> Project: Harmony
> Issue Type: Improvement
> Components: Classlib
> Reporter: Sergey Dmitriev
> Assignee: Tim Ellison
> Attachments: cvk.patch
>
>
> Some time ago I've found a piece of code in NIO which can be simply improved.
> AbstractSelectableChannel.java:
> /**
> * Returns true if the keyList contains at least 1 valid key and false otherwise.
> */
> private synchronized boolean containsValidKeys() {
> - for (Iterator<SelectionKey> iter = keyList.iterator(); iter.hasNext();) {
> - SelectionKey key = iter.next();
> + for (int i=0; i<keyList.size(); i++) {
> + SelectionKey key = keyList.get(i);
> if (key != null && key.isValid()) {
> return true;
> }
> }
> }
> Just don't create an Iterator here. Indeed no big deal, but it would be just pity to loose this discovery. :)
> I even created the mini test to demonstrate the benefit of my patch (approx 10%).
> {guy@nowhere:~/tmp} cat cvk.java
> import java.io.*;
> import java.nio.channels.*;
> // cvk: containsValidKeys()
> public class cvk {
> static int numOfIters = 10;
> static int numOfConfigures = 10*1000*1000;
> public static void main(String[] args) throws Exception {
> ServerSocketChannel ssc = ServerSocketChannel.open();
> for (int i=0; i<numOfIters; i++) {
> long millis = System.currentTimeMillis();
> for (int j=0; j<numOfConfigures; j++) {
> ssc.configureBlocking(false);
> ssc.configureBlocking(true);
> }
> System.out.println(System.currentTimeMillis() - millis);
> }
> }
> }
> {guy@nowhere:~/tmp} ~/harmony.29sep.my.nocvk/bin/java -Xem:server cvk
> 7049
> 6149
> 6134
> 6125
> 6140
> 6139
> 6131
> 6142
> 6148
> 6200
> {guy@nowhere:~/tmp} ~/harmony.29sep.my.cvk/bin/java -Xem:server cvk
> 5769
> 5499
> 5491
> 5497
> 5483
> 5474
> 5466
> 5470
> 5453
> 5478
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.