You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by "Alexey Varlamov (JIRA)" <ji...@apache.org> on 2007/10/26 07:24:50 UTC
[jira] Commented: (HARMONY-5025) [classlib][nio] make
AbstractSelectableChannel.containsValidKeys() a little bit faster
[ 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.