Potentially useless allocations when checking a field cardinality

👋🏻 Hey folks In a service running JanusGraph embedded, I observed a number of sizeable allocations coming from JanusGraphVertexFeatures#getCardinality (https://github.com/JanusGraph/janusgraph/blob/2c71b378339a3ab49b961eef29b5a042d018f513/janusgraph-core/src/main/java/org/janusgraph/graphdb/tinkerpop/JanusGraphFeatures.java#L161-L169). From a profile (attached), it looks like - A StandardJanusGraphTx transaction is created when checking a vertex property's cardinality (https://github.com/JanusGraph/janusgraph/blob/2c71b378339a3ab49b961eef29b5a042d018f513/janusgraph-core/src/main/java/org/janusgraph/graphdb/tinkerpop/JanusGraphFeatures.java#L162). - The transaction will allocate a CaffeineVertexCache (https://github.com/JanusGraph/janusgraph/blob/2c71b378339a3ab49b961eef29b5a042d018f513/janusgraph-core/src/main/java/org/janusgraph/graphdb/transaction/StandardJanusGraphTx.java#L335). - The CaffeineVertexCache internally creates a NonBlockingHashMap (https://github.com/JanusGraph/janusgraph/blob/master/janusgraph-core/src/main/java/org/janusgraph/graphdb/transaction/vertexcache/CaffeineVertexCache.java#L44) which initial size is configured in the GraphDatabaseConfiguration class or the graph configuration (https://github.com/JanusGraph/janusgraph/blob/2c71b378339a3ab49b961eef29b5a042d018f513/janusgraph-core/src/main/java/org/janusgraph/graphdb/configuration/GraphDatabaseConfiguration.java#L1613-L1620). I believe the sizeable allocations come from having batch loading enabled (making the initial NonBlockingHashMap size 4096) and can be fixed by updating the graph configuration. That said, we could maybe disable the vertex cache by default when checking a vertex property's cardinality? As in this change: https://github.com/JanusGraph/janusgraph/pull/4506/files Happy to hear any feedback. Thanks!
No description
1 Reply
Bo
Bo3mo ago
love the flame chart
Want results from more Discord servers?
Add your server