aboutsummaryrefslogtreecommitdiff
path: root/src/test/java/com/google/escapevelocity/ReferenceNodeTest.java
diff options
context:
space:
mode:
authoremcmanus <emcmanus@google.com>2019-04-30 16:51:41 -0400
committerRon Shapiro <ronshapiro@google.com>2019-04-30 16:56:50 -0400
commitb515e83e6e713ff7ae6035c181b968ed67cb59db (patch)
tree7dee6967f17c226b0fa2a14980628e86a79dd7d1 /src/test/java/com/google/escapevelocity/ReferenceNodeTest.java
parent4bb1d7445fc2f99dbf4371e6f3177b5b1e4c5d60 (diff)
downloadescapevelocity-b515e83e6e713ff7ae6035c181b968ed67cb59db.tar.gz
Sync from internal
--- Cache Method objects per template rather than per template evaluation. In a somewhat artificial benchmark, this sped up evaluation by 35%. The benchmark compiles AutoValueTest.java 100 times, and measures how much time was spent by AutoValueProcessor in template evaluation. AutoValueTest.java has 40 @AutoValue classes, and each of those triggers a separate template evaluation. Previously every one of those created a new Method cache (MethodFinder object). Now only the first one (on each iteration of the benchmark) does. Compilation runs will rarely have as many as 40 @AutoValue classes, but they have often have several, so there is still some benefit. According to this benchmark, EscapeVelocity and Apache Velocity now have indistinguishable performance. Internal change: 245835876 --- Avoid excessive reflection overhead by caching the results of method lookups. On an ad-hoc benchmark this improved template evaluation time by 38%. That means that code generators such as AutoValue that use EscapeVelocity should see a substantial speedup. Internal change: 244671738 --- If $foo is a Map then Velocity interprets $foo.bar the same as $foo["bar"]. Previously EscapeVelocity interpreted it the same as for other objects, by looking for a getBar() method (or boolean isBar()). It turns out that autoannotation.vm was depending on the old behaviour, so fix that. Internal change: 244364373
Diffstat (limited to 'src/test/java/com/google/escapevelocity/ReferenceNodeTest.java')
-rw-r--r--src/test/java/com/google/escapevelocity/ReferenceNodeTest.java18
1 files changed, 2 insertions, 16 deletions
diff --git a/src/test/java/com/google/escapevelocity/ReferenceNodeTest.java b/src/test/java/com/google/escapevelocity/ReferenceNodeTest.java
index 3e784f6..b1759bd 100644
--- a/src/test/java/com/google/escapevelocity/ReferenceNodeTest.java
+++ b/src/test/java/com/google/escapevelocity/ReferenceNodeTest.java
@@ -17,15 +17,11 @@ package com.google.escapevelocity;
import static com.google.common.truth.Truth.assertThat;
-import com.google.escapevelocity.ReferenceNode.MethodReferenceNode;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.common.primitives.Primitives;
import com.google.common.truth.Expect;
-import java.lang.reflect.Method;
-import java.lang.reflect.Modifier;
-import java.util.Collections;
-import java.util.Map;
+import com.google.escapevelocity.ReferenceNode.MethodReferenceNode;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -85,22 +81,12 @@ public class ReferenceNodeTest {
MethodReferenceNode.primitiveTypeIsAssignmentCompatible(to, from);
expect
.withMessage(from + " assignable to " + to)
- .that(expected).isEqualTo(actual);
+ .that(actual).isEqualTo(expected);
}
}
}
@Test
- public void testVisibleMethod() throws Exception {
- Map<String, String> map = Collections.singletonMap("foo", "bar");
- Class<?> mapClass = map.getClass();
- assertThat(Modifier.isPublic(mapClass.getModifiers())).isFalse();
- Method size = map.getClass().getMethod("size");
- Method visibleSize = ReferenceNode.visibleMethod(size, mapClass);
- assertThat(visibleSize.invoke(map)).isEqualTo(1);
- }
-
- @Test
public void testCompatibleArgs() {
assertThat(MethodReferenceNode.compatibleArgs(
new Class<?>[]{int.class}, ImmutableList.of((Object) 5))).isTrue();