Charles Oliver Nutter wrote:
I thought I'd run some numbers to see what size variable scopes appear
in typical applications. Currently, for heap-based scoping, we optimize
up to 4 local variables in fields, and anything larger we only use an
array structure to contain. Here's the breakdown for a few apps/scripts:
Here's the diff to do this analysis again, should anyone want to:
diff --git a/src/org/jruby/parser/StaticScope.java
b/src/org/jruby/parser/StaticScope.java
index 03f51fb..f9deb44 100644
--- a/src/org/jruby/parser/StaticScope.java
+++ b/src/org/jruby/parser/StaticScope.java
@@ -30,6 +30,10 @@ package org.jruby.parser;
import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
import org.jruby.Ruby;
import org.jruby.RubyModule;
import org.jruby.RubyObject;
@@ -85,10 +89,28 @@ public abstract class StaticScope implements
Serializable {
private boolean isBackrefLastlineScope = false;
private DynamicScope dummyScope = new NoVarsDynamicScope(this);
+
+ static List<StaticScope> scopes = new ArrayList<StaticScope>();
+
+ static {
+ Runtime.getRuntime().addShutdownHook(new Thread() {
+ public void run() {
+ Map<Integer, Integer> sizes = new HashMap<Integer,
Integer>();
+ for (StaticScope scope : scopes) {
+ Integer count = sizes.get(scope.getVariables().length);
+ count = count == null ? 1 : count + 1;
+ sizes.put(scope.getVariables().length, count);
+ }
+ System.out.println(sizes);
+ }
+ });
+ }
protected StaticScope(StaticScope enclosingScope, String[] names) {
assert names != null : "names is not null";
assert namesAreInterned(names);
+
+ scopes.add(this);
this.enclosingScope = enclosingScope;
this.variableNames = names;
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email