changeset 1759:72380e12d86c

performance: add @cachedUriValues Ignore-this: f3a707bc25acc028dedd2f115a5d17e5
author Drew Perttula <drewp@bigasterisk.com>
date Tue, 29 May 2018 07:00:37 +0000
parents 887eb43b389a
children f2f2206281c4
files light9/web/graph.coffee
diffstat 1 files changed, 10 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/light9/web/graph.coffee	Mon May 28 00:25:46 2018 +0000
+++ b/light9/web/graph.coffee	Tue May 29 07:00:37 2018 +0000
@@ -153,7 +153,8 @@
     # if we had a Store already, this lets N3.Store free all its indices/etc
     @graph = N3.Store()
     @_addPrefixes(@prefixes)
-    @cachedFloatValues = new Map()
+    @cachedFloatValues = new Map() # s + '|' + p -> number
+    @cachedUriValues = new Map() # s + '|' + p -> Uri
 
   _clearGraphOnNewConnection: -> # must not send a patch to the server!
     log('graph: clearGraphOnNewConnection')
@@ -228,6 +229,7 @@
     #
     # This is the only method that writes to @graph!
     @cachedFloatValues.clear()
+    @cachedUriValues.clear()
     for quad in patch.delQuads
       #log("remove #{JSON.stringify(quad)}")
       did = @graph.removeQuad(quad)
@@ -291,7 +293,13 @@
     @_singleValue(s, p).value
     
   uriValue: (s, p) ->
-    @_singleValue(s, p)
+    key = s.value + '|' + p.value
+    hit = @cachedUriValues.get(key)
+    return hit if hit != undefined
+
+    ret = @_singleValue(s, p)
+    @cachedUriValues.set(key, ret)
+    return ret
 
   labelOrTail: (uri) ->
     try