Repository navigation
Cache the edge reference - #918
Conversation
This eschews object overhead and resulting boxing/unboxing while retaining the ability to cache per-entry in the adjacancy matrix (by using a short with effectively three states) Additionally, due to the missing object header, this will be more space efficient.
Reduces memory footprint by 2x.
jsichi
left a comment
There was a problem hiding this comment.
Regarding the array representation, java.util.BitSet would be much more compact (two bits per entry), but I dunno about the performance.
| { | ||
|
|
||
| if (cacheEdges) { | ||
| final E cache = edgeCache[v1Number*vertexCount+v2Number]; |
There was a problem hiding this comment.
In the case where the edge doesn't exist, we will always have to re-confirm that (making the caching ineffective). If we agree to always combine the edge existence cache with the edge reference cache, then we can make use of the edge existence cache to solve that.
There was a problem hiding this comment.
I don't think getEdge is ever called if !hasEdge. That being said, would you want something like:
if(cacheEdges){
if(!hasEdge(v1Number, v2Number) return null; // assuming this is the correct return value?
final E cache = edgeCache[v1Number*vertexCount+v2Number];
....
}
There was a problem hiding this comment.
It's possible to further optimize it to avoid calling both containsEdge and getEdge on the first (uncached) call. In other words:
- check cache bit
- if already cached, just do array lookup
- if not cached yet, call getEdge, and update both caches based on result (getEdge returns null whenever containsEdge would have returned false)
There was a problem hiding this comment.
I actually think one may want to do this in hasEdge - namely instead of calling containsEdge, call getEdge and update both cache matrices.
I believe the typical use case is calls to hasEdge followed by getEdge calls, so I'd like to optimize that path.
I'll implement it once #914 lands
Store cache address.
…ion." This reverts commit efa2d48.
|
OK, I merged #914, so you can go ahead and finish this one. |
|
@jsichi done, have a look. This improves end-to-end performance in my tests for a 38 noded graph with a 10 node subgraph by a little over 20%. |
|
Thanks! |
Follow-up to #914.
Avoid pointer chasing by using a flattened matrix representation. This should per reference consume 4bytes with compressed JVM pointers, 8bytes otherwise.
HISTORY.mdorCONTRIBUTORS.md