[jboss-dev-forums] [Design of POJO Server] - JBVFS-25 - Optimizing the VFS PathTokenizer

adrian@jboss.org do-not-reply at jboss.com
Wed May 21 05:27:43 EDT 2008


It looks to me that the problem with the PathTokenizer
(and the related findChild() is all the string comparisons.


  |    public static String[] getTokens(String path)
  |    {
  |       if (path == null)
  |          throw new IllegalArgumentException("Null path");
  | 
  |       StringTokenizer tokenizer = new StringTokenizer(path, "/");
  |       int count = tokenizer.countTokens();
  |       if (count == 0)
  |          return null;
  | 
  |       String[] tokens = new String[count];
  |       int i = 0;
  |       while (tokenizer.hasMoreTokens())
  |       {
  |          String token = tokenizer.nextToken();
  | 
  |          if ("".equals(token))
  |             throw new IllegalArgumentException("A path element is empty: " + path);
  | 
  |          tokens[i++] = token;
  |       }
  |       return tokens;
  |    }
  | 
  |    /**
  |     * Is current token.
  |     *
  |     * @param token the token to check
  |     * @return true if token matches current path token
  |     */
  |    public static boolean isCurrentToken(String token)
  |    {
  |       return CURRENT_PATH.equals(token);
  |    }
  | 
  |    /**
  |     * Is reverse token.
  |     *
  |     * @param token the token to check
  |     * @return true if token matches reverse path token
  |     */
  |    public static boolean isReverseToken(String token)
  |    {
  |       return REVERSE_PATH.equals(token);
  |    }
  | 

1) If StringTokenizer was replaced with an optimized lexer
(e.g. like the one used to parse system property references from strings in common-core)
then the check for an empty token could be done inline instead of string
comparison.

2) Similarly the usage of "." and ".." as tokens could be optimized to
return the singleton reference of these strings in the token array. 
The code then check for object equality, e.g.


  |    public static boolean isCurrentToken(String token)
  |    {
  | --      return CURRENT_PATH.equals(token);
  | ++      return CURRENT_PATH == token;
  |    }
  | 

It's worth while optimizing this code since it is showing up as a hotspot.
It will be hotspot at runtime as well (not just boot time) since this code
gets invoked on every classloading request (that isn't to a previously cached
or blacklisted class) - since the classloader uses the VFS.

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4152255#4152255

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4152255



More information about the jboss-dev-forums mailing list