You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@mahout.apache.org by Jeff Eastman <jd...@windwardsolutions.com> on 2009/06/22 21:48:32 UTC

Re: svn commit: r787320 - /lucene/mahout/trunk/core/src/main/java/org/apache/mahout/matrix/AbstractVector.java

Should have tried a performance test, since this does not affect 
deserialization times (over 100k iterations) with or without the 
optimization.

jeastman@apache.org wrote:
> Author: jeastman
> Date: Mon Jun 22 17:26:23 2009
> New Revision: 787320
>
> URL: http://svn.apache.org/viewvc?rev=787320&view=rev
> Log:
> MAHOUT-137: Added most-recent class caching to AbstractVector.readVector() on the belief that Vector instantiations in a single VM will use the same Vector type
>
> Modified:
>     lucene/mahout/trunk/core/src/main/java/org/apache/mahout/matrix/AbstractVector.java
>
> Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/matrix/AbstractVector.java
> URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/matrix/AbstractVector.java?rev=787320&r1=787319&r2=787320&view=diff
> ==============================================================================
> --- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/matrix/AbstractVector.java (original)
> +++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/matrix/AbstractVector.java Mon Jun 22 17:26:23 2009
> @@ -492,6 +492,12 @@
>      set(index, value);
>    }
>  
> +  // cache most recent vector instance class name
> +  private static String instanceClassName;
> +
> +  // cache most recent vector instance class
> +  private static Class<? extends Vector> instanceClass;
> +
>    /**
>     * Read and return a vector from the input
>     * 
> @@ -503,8 +509,11 @@
>      String vectorClassName = in.readUTF();
>      Vector vector;
>      try {
> -      vector = Class.forName(vectorClassName).asSubclass(Vector.class)
> -          .newInstance();
> +      if (!vectorClassName.equals(instanceClassName)) {
> +        instanceClassName = vectorClassName;
> +        instanceClass = Class.forName(vectorClassName).asSubclass(Vector.class);
> +      }
> +      vector = instanceClass.newInstance();
>      } catch (ClassNotFoundException e) {
>        throw new RuntimeException(e);
>      } catch (IllegalAccessException e) {
>
>
>
>
>