You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tinkerpop.apache.org by otaviojava <gi...@git.apache.org> on 2018/10/03 17:25:45 UTC

[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 <ot...@...>
Date:   2018-10-03T17:17:07Z

    Optimazes Map with enum using the EnumMap implementation

----


---

[GitHub] tinkerpop issue #948: Optimizes Map with enum using the EnumMap implementati...

Posted by spmallette <gi...@git.apache.org>.
Github user spmallette commented on the issue:

    https://github.com/apache/tinkerpop/pull/948
  
    merged to all release branches - thanks @otaviojava 


---

[GitHub] tinkerpop issue #948: Optimizes Map with enum using the EnumMap implementati...

Posted by dkuppitz <gi...@git.apache.org>.
Github user dkuppitz commented on the issue:

    https://github.com/apache/tinkerpop/pull/948
  
    Although this looks like a very reasonable change and I don't have any objections, could you please run some benchmarks to show what we gain by this change?


---

[GitHub] tinkerpop issue #948: Optimizes Map with enum using the EnumMap implementati...

Posted by dkuppitz <gi...@git.apache.org>.
Github user dkuppitz commented on the issue:

    https://github.com/apache/tinkerpop/pull/948
  
    That's the kind of benchmark I was looking for. I don't think it needs to be part of the project (these micro-benchmarks always seem to be too unstable and making them part of the test suite usually just makes the builds fail at some point) - thus a manual test is good enough.
    
    VOTE + 1


---

[GitHub] tinkerpop pull request #948: Optimizes Map with enum using the EnumMap imple...

Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the pull request at:

    https://github.com/apache/tinkerpop/pull/948


---

[GitHub] tinkerpop issue #948: Optimizes Map with enum using the EnumMap implementati...

Posted by otaviojava <gi...@git.apache.org>.
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(__.<Vertex>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(__.<Vertex>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(__.<Vertex>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(__.<Vertex>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.setEdgeFilter(__.<Vertex>bothE("created").has("weight", 32));
                    assertTrue(graphFilter.hasEdgeFilter());
                    assertEquals(Collections.singleton("created"), graphFilter.getLegallyPositiveEdgeLabels(Direction.OUT));
                    assertEquals(Collections.singleton("created"), graphFilter.getLegallyPositiveEdgeLabels(Direction.IN));
                    assertEquals(Collections.singleton("created"), graphFilter.getLegallyPositiveEdgeLabels(Direction.BOTH));
                    //
                    graphFilter = new GraphFilter();
                    graphFilter.setEdgeFilter(__.union(__.outE("created"), __.inE("likes")));
                    assertTrue(graphFilter.hasEdgeFilter());
                    assertEquals(Collections.singleton("created"), graphFilter.getLegallyPositiveEdgeLabels(Direction.OUT));
                    assertEquals(Collections.singleton("likes"), graphFilter.getLegallyPositiveEdgeLabels(Direction.IN));
                    assertEquals(Collections.emptySet(), graphFilter.getLegallyPositiveEdgeLabels(Direction.BOTH));
                    //
                    graphFilter = new GraphFilter();
                    graphFilter.setEdgeFilter(__.union(__.outE("created"), __.inE("likes", "created")));
                    assertTrue(graphFilter.hasEdgeFilter());
                    assertEquals(Collections.singleton("created"), graphFilter.getLegallyPositiveEdgeLabels(Direction.OUT));
                    assertEquals(new HashSet<>(Arrays.asList("likes", "created")), graphFilter.getLegallyPositiveEdgeLabels(Direction.IN));
                    assertEquals(Collections.singleton("created"), graphFilter.getLegallyPositiveEdgeLabels(Direction.BOTH));
                }
                long end = System.currentTimeMillis() - start;
                System.out.println(end);
            }
    ```
    
    ## EnumMap
    Minimum: 3
    Maximum: 35
    Range: 32
    Count: 99
    Mean: 7.646
    Median: 6
    Mode: 6
    
    ## HashMap
    
    Minimum: 6
    Maximum: 56
    Range: 53
    Count: 99
    Mean: 9.434
    Median: 9
    Mode: 8


---

[GitHub] tinkerpop issue #948: Optimizes Map with enum using the EnumMap implementati...

Posted by spmallette <gi...@git.apache.org>.
Github user spmallette commented on the issue:

    https://github.com/apache/tinkerpop/pull/948
  
    All tests pass with `docker/build.sh -t -n -i`
    
    VOTE +1


---

[GitHub] tinkerpop issue #948: Optimizes Map with enum using the EnumMap implementati...

Posted by robertdale <gi...@git.apache.org>.
Github user robertdale commented on the issue:

    https://github.com/apache/tinkerpop/pull/948
  
    VOTE +1


---