[GitHub] tinkerpop pull request #951: Optimizes Set with enum using the EnumSet imple...
GitHub user otaviojava opened a pull request: https://github.com/apache/tinkerpop/pull/951 Optimizes Set with enum using the EnumSet implementation [tp32] This PR replaces the HashSet implementation to [EnumSet](https://docs.oracle.com/javase/7/docs/api/java/util/EnumSet.html) that as its documentation says: > A specialized Set implementation for use with enum types. All of the elements in an enum set must come from a single enum type that is specified, explicitly or implicitly, when the set is created. Enum sets are represented internally as bit vectors. This representation is extremely compact and efficient. The space and time performance of this class should be good enough to allow its use as a high-quality, typesafe alternative to traditional int-based "bit flags." Even bulk operations (such as containsAll and retainAll) should run very quickly if their argument is also an enum set. That is a continuation of the PR: https://github.com/apache/tinkerpop/pull/948 that has the same benchmark value. You can merge this pull request into a Git repository by running: $ git pull https://github.com/otaviojava/tinkerpop tp32_enum_set Alternatively you can review and apply these changes as the patch at: https://github.com/apache/tinkerpop/pull/951.patch To close this pull request, make a commit to your master/trunk branch with (at least) the following in the commit message: This closes #951 commit 68f069d6adfe99e6a4d5fa96b7b88c5137773626 Author: Otavio Santana Date: 2018-10-05T10:57:30Z repleaces EnumSet to HashSet ---
[GitHub] tinkerpop issue #948: Optimizes Map with enum using the EnumMap implementati...
Github user otaviojava commented on the issue: https://github.com/apache/tinkerpop/pull/948 @dkuppitz do you have any benchmarks that you in the project use? ```java for (int i = 0; i < 100; i++) { long start = System.currentTimeMillis(); for (int index = 0; index < 100; index++) { GraphFilter graphFilter = new GraphFilter(); assertFalse(graphFilter.hasEdgeFilter()); assertEquals(Collections.singleton(null), graphFilter.getLegallyPositiveEdgeLabels(Direction.OUT)); assertEquals(Collections.singleton(null), graphFilter.getLegallyPositiveEdgeLabels(Direction.IN)); assertEquals(Collections.singleton(null), graphFilter.getLegallyPositiveEdgeLabels(Direction.BOTH)); // graphFilter = new GraphFilter(); graphFilter.setEdgeFilter(__.outE("created")); assertTrue(graphFilter.hasEdgeFilter()); assertEquals(Collections.singleton("created"), graphFilter.getLegallyPositiveEdgeLabels(Direction.OUT)); assertEquals(Collections.emptySet(), graphFilter.getLegallyPositiveEdgeLabels(Direction.IN)); assertEquals(Collections.emptySet(), graphFilter.getLegallyPositiveEdgeLabels(Direction.BOTH)); // graphFilter = new GraphFilter(); graphFilter.setEdgeFilter(__.outE()); assertTrue(graphFilter.hasEdgeFilter()); assertEquals(Collections.singleton(null), graphFilter.getLegallyPositiveEdgeLabels(Direction.OUT)); assertEquals(Collections.emptySet(), graphFilter.getLegallyPositiveEdgeLabels(Direction.IN)); assertEquals(Collections.emptySet(), graphFilter.getLegallyPositiveEdgeLabels(Direction.BOTH)); // graphFilter = new GraphFilter(); graphFilter.setEdgeFilter(__.outE("created").has("weight", 32)); assertTrue(graphFilter.hasEdgeFilter()); assertEquals(Collections.singleton("created"), graphFilter.getLegallyPositiveEdgeLabels(Direction.OUT)); assertEquals(Collections.emptySet(), graphFilter.getLegallyPositiveEdgeLabels(Direction.IN)); assertEquals(Collections.emptySet(), graphFilter.getLegallyPositiveEdgeLabels(Direction.BOTH)); // graphFilter = new GraphFilter(); graphFilter.setEdgeFilter(__.identity().outE("created")); assertTrue(graphFilter.hasEdgeFilter()); assertEquals(Collections.singleton(null), graphFilter.getLegallyPositiveEdgeLabels(Direction.OUT)); assertEquals(Collections.singleton(null), graphFilter.getLegallyPositiveEdgeLabels(Direction.IN)); assertEquals(Collections.singleton(null), graphFilter.getLegallyPositiveEdgeLabels(Direction.BOTH)); // graphFilter = new GraphFilter(); graphFilter.setEdgeFilter(__.bothE()); assertTrue(graphFilter.hasEdgeFilter()); assertEquals(Collections.singleton(null), graphFilter.getLegallyPositiveEdgeLabels(Direction.OUT)); assertEquals(Collections.singleton(null), graphFilter.getLegallyPositiveEdgeLabels(Direction.IN)); assertEquals(Collections.singleton(null), graphFilter.getLegallyPositiveEdgeLabels(Direction.BOTH)); // graphFilter = new GraphFilter(); graphFilter.setEdgeFilter(__.bothE().has("weight", 32)); assertTrue(graphFilter.hasEdgeFilter()); assertEquals(Collections.singleton(null), graphFilter.getLegallyPositiveEdgeLabels(Direction.OUT)); assertEquals(Collections.singleton(null), graphFilter.getLegallyPositiveEdgeLabels(Direction.IN)); assertEquals(Collections.singleton(null), graphFilter.getLegallyPositiveEdgeLabels(Direction.BOTH)); // graphFilter = new GraphFilter(); graphFilter.setEdgeFilter(__.bothE().limit(0)); assertTrue(graphFilter.hasEdgeFilter()); assertEquals(Collections.emptySet(), graphFilter.getLegallyPositiveEdgeLabels(Direction.OUT)); assertEquals(Collections.emptySet(), graphFilter.getLegallyPositiveEdgeLabels(Direction.IN)); assertEquals(Collections.emptySet(), graphFilter.getLegallyPositiveEdgeLabels(Direction.BOTH)); // graphFilter = new GraphFilter(); graphFilter.setEdgeF
[GitHub] tinkerpop pull request #948: Optimizes Map with enum using the EnumMap imple...
GitHub user otaviojava opened a pull request: https://github.com/apache/tinkerpop/pull/948 Optimizes Map with enum using the EnumMap implementation This PR replaces the HashMap implementation to [EnumMap](https://docs.oracle.com/javase/8/docs/api/java/util/EnumMap.html) that as its documentation says: "A specialized Map implementation for use with enum type keys. All of the keys in an enum map must come from a single enum type that is specified, explicitly or implicitly, when the map is created. Enum maps are represented internally as arrays. This representation is extremely compact and efficient." You can merge this pull request into a Git repository by running: $ git pull https://github.com/otaviojava/tinkerpop tp32_enum_map Alternatively you can review and apply these changes as the patch at: https://github.com/apache/tinkerpop/pull/948.patch To close this pull request, make a commit to your master/trunk branch with (at least) the following in the commit message: This closes #948 commit 9e1865a98d9350451d29dc837e053109d714d7e3 Author: Otavio Santana Date: 2018-10-03T17:17:07Z Optimazes Map with enum using the EnumMap implementation ---
[GitHub] tinkerpop issue #920: optmizes collection copy with Collections addAll
Github user otaviojava commented on the issue: https://github.com/apache/tinkerpop/pull/920 @spmallette done, sorry by the delay. @dkuppitz thank you for the support ---
[GitHub] tinkerpop issue #920: optmizes collection copy with Collections addAll
Github user otaviojava commented on the issue: https://github.com/apache/tinkerpop/pull/920 hey @spmallette yes, but just next week ---
[GitHub] tinkerpop pull request #920: optmizes collection copy with Collections addAl...
GitHub user otaviojava opened a pull request: https://github.com/apache/tinkerpop/pull/920 optmizes collection copy with Collections addAll Copying of array contents to a collection where each element is added individually using a for a loop. We can be replaced by a call to Collections.addAll(). As the documentation says: > Adds all of the specified elements to the specified collection. Elements to be added may be specified individually or as an array. The behavior of this convenience method is identical to that of c.addAll(Arrays.asList(elements)), but this method is likely to run significantly faster under most implementations. When elements are specified individually, this method provides a convenient way to add a few elements to an existing collection: https://docs.oracle.com/javase/8/docs/api/java/util/Collections.html#addAll-java.util.Collection-T...- In my experience using either Collections.addll or Collections.addAll used to be 30% faster then add from loop. You can merge this pull request into a Git repository by running: $ git pull https://github.com/otaviojava/tinkerpop optmizes_collections_copy_tp32 Alternatively you can review and apply these changes as the patch at: https://github.com/apache/tinkerpop/pull/920.patch To close this pull request, make a commit to your master/trunk branch with (at least) the following in the commit message: This closes #920 commit 0e34073d8a756a52eda571bd9ddac0b94b42d54a Author: Otavio Santana Date: 2018-08-22T19:45:19Z optmizes collection copy with Collections addAll ---
[GitHub] tinkerpop issue #919: String loop to String builder [tp32]
Github user otaviojava commented on the issue: https://github.com/apache/tinkerpop/pull/919 @spmallette @robertdale When I changed the branch to tp32. When execute this code: `return new ASTTransformationCustomizer(InterpreterMode.class);` It returns an NPE, I checked the code. ```java private static CompilePhase findPhase(ASTTransformation transformation) { if (transformation==null) throw new IllegalArgumentException("Provided transformation must not be null") final Class clazz = transformation.class//this line returns a NPE final GroovyASTTransformation annotation = clazz.getAnnotation(GroovyASTTransformation) if (annotation==null) throw new IllegalArgumentException("Provided ast transformation is not annotated with "+GroovyASTTransformation.name) annotation.phase() } ``` The file: ASTTransformationCustomizer.groovy I did not change the code at this point. Suggestions? ---
[GitHub] tinkerpop pull request #919: String loop to String builder [tp32]
Github user otaviojava commented on a diff in the pull request: https://github.com/apache/tinkerpop/pull/919#discussion_r211956497 --- Diff: gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/DefaultTraversalMetrics.java --- @@ -286,10 +286,10 @@ private void appendMetrics(final Collection metrics, final St private static String padLeft(final String text, final int amountToPad) { // not sure why this method needed to exist. stupid string format stuff and commons utilities wouldn't // work for some reason in the context this method was used above. -String newText = text; +final StringBuilder newText = new StringBuilder(text); for (int ix = 0; ix < amountToPad; ix++) { -newText = " " + newText; +newText.insert(0, " "); } --- End diff -- Done, thank you. ---
[GitHub] tinkerpop pull request #919: String loop to String builder [tp32]
Github user otaviojava commented on a diff in the pull request: https://github.com/apache/tinkerpop/pull/919#discussion_r211956428 --- Diff: gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/DefaultTraversalMetrics.java --- @@ -208,14 +208,14 @@ private void handleNestedTraversals(final Traversal.Admin traversal, final Mutab private void appendMetrics(final Collection metrics, final StringBuilder sb, final int indent) { // Append each StepMetric's row. indexToLabelMap values are ordered by index. for (Metrics m : metrics) { -String rowName = m.getName(); +final StringBuilder metricName = new StringBuilder(m.getName()); // Handle indentation for (int ii = 0; ii < indent; ii++) { -rowName = " " + rowName; +metricName.insert(0, " "); } --- End diff -- Done in both, thank you. ---
[GitHub] tinkerpop pull request #919: String loop to String builder [master]
Github user otaviojava commented on a diff in the pull request: https://github.com/apache/tinkerpop/pull/919#discussion_r211950542 --- Diff: gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/DefaultTraversalMetrics.java --- @@ -208,14 +208,14 @@ private void handleNestedTraversals(final Traversal.Admin traversal, final Mutab private void appendMetrics(final Collection metrics, final StringBuilder sb, final int indent) { // Append each StepMetric's row. indexToLabelMap values are ordered by index. for (Metrics m : metrics) { -String rowName = m.getName(); +final StringBuilder metricName = new StringBuilder(m.getName()); // Handle indentation for (int ii = 0; ii < indent; ii++) { -rowName = " " + rowName; +metricName.insert(0, " "); } --- End diff -- Do you mean this way? ```java private static String padLeft(final String text, final int amountToPad) { // not sure why this method needed to exist. stupid string format stuff and commons utilities wouldn't // work for some reason in the context this method was used above. final StringBuilder newText = new StringBuilder(); for (int ix = 0; ix < amountToPad; ix++) { newText.append(" "); } newText.append(text); return newText.toString(); } ``` ---
[GitHub] tinkerpop issue #919: String loop to String builder [master]
Github user otaviojava commented on the issue: https://github.com/apache/tinkerpop/pull/919 @spmallette done. ---
[GitHub] tinkerpop issue #919: String loop to String builder [master]
Github user otaviojava commented on the issue: https://github.com/apache/tinkerpop/pull/919 @robertdale I think so, after the merge in the master, I can create a second one to bot tp32 and tp33. But, I don't know. That is my first contribution to the project. ---
[GitHub] tinkerpop pull request #919: String loop to String builder
Github user otaviojava commented on a diff in the pull request: https://github.com/apache/tinkerpop/pull/919#discussion_r211940698 --- Diff: gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/DefaultTraversalMetrics.java --- @@ -286,10 +286,10 @@ private void appendMetrics(final Collection metrics, final St private static String padLeft(final String text, final int amountToPad) { // not sure why this method needed to exist. stupid string format stuff and commons utilities wouldn't // work for some reason in the context this method was used above. -String newText = text; +final StringBuilder newText = new StringBuilder(text); for (int ix = 0; ix < amountToPad; ix++) { -newText = " " + newText; +newText.insert(0, " "); } --- End diff -- That is the same previous behavior, but using StringBuilder this time. https://docs.oracle.com/javase/8/docs/api/java/lang/StringBuilder.html#insert-int-java.lang.String- ---
[GitHub] tinkerpop pull request #919: String loop to String builder
Github user otaviojava commented on a diff in the pull request: https://github.com/apache/tinkerpop/pull/919#discussion_r211940616 --- Diff: gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/DefaultTraversalMetrics.java --- @@ -208,14 +208,14 @@ private void handleNestedTraversals(final Traversal.Admin traversal, final Mutab private void appendMetrics(final Collection metrics, final StringBuilder sb, final int indent) { // Append each StepMetric's row. indexToLabelMap values are ordered by index. for (Metrics m : metrics) { -String rowName = m.getName(); +final StringBuilder metricName = new StringBuilder(m.getName()); // Handle indentation for (int ii = 0; ii < indent; ii++) { -rowName = " " + rowName; +metricName.insert(0, " "); } --- End diff -- That is the same previous behavior, but using StringBuilder this time. https://docs.oracle.com/javase/8/docs/api/java/lang/StringBuilder.html#insert-int-java.lang.String- ---
[GitHub] tinkerpop issue #919: String loop to String builder
Github user otaviojava commented on the issue: https://github.com/apache/tinkerpop/pull/919 There are optimizations in Java 8 to String, however, it does not cover to String in a loop. Yes, I checked also in the bytecode. After that, I put the final var. Thank you for the help. ---
[GitHub] tinkerpop pull request #919: String loop to String builder
GitHub user otaviojava opened a pull request: https://github.com/apache/tinkerpop/pull/919 String loop to String builder String concatenation in loops. As every String concatenation copies the whole String, usually it is preferable to replace it with explicit calls to StringBuilder.append() or StringBuffer.append(). You can merge this pull request into a Git repository by running: $ git pull https://github.com/otaviojava/tinkerpop string_string_builder Alternatively you can review and apply these changes as the patch at: https://github.com/apache/tinkerpop/pull/919.patch To close this pull request, make a commit to your master/trunk branch with (at least) the following in the commit message: This closes #919 commit a63df818d54fdb9baee75ce4101e4d5482e069c1 Author: Otavio Santana Date: 2018-08-22T12:01:08Z repleace String loop to String builder ---