Skip to content

Commit 05f7ad4

Browse files
committed
data: add definitions-cache-[FAMILY].db databases
Lookup if a definition exists is taking too long to render source code. Generate small databases that only tell us if a definition exists for a given family. Because the database is much smaller, it is faster to query. Many URLs could only be queried at 12 req/s. With that patch, I can do >80 req/s on the same URLs, with the same config. We generate the caches from update.py. We also add an edge-case to generate the files (if they don't exist) even if no new tag exists. Signed-off-by: Théo Lebrun <theo.lebrun@bootlin.com>
1 parent 1f5f16d commit 05f7ad4

3 files changed

Lines changed: 25 additions & 3 deletions

File tree

elixir/data.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,12 @@ def __init__(self, dir, readonly=True, dtscomp=False, shared=False):
201201
# Map serial number to filename
202202
self.vers = BsdDB(dir + '/versions.db', ro, PathList, shared=shared)
203203
self.defs = BsdDB(dir + '/definitions.db', ro, DefList, shared=shared)
204+
self.defs_cache = {}
205+
NOOP = lambda x: x
206+
self.defs_cache['C'] = BsdDB(dir + '/definitions-cache-C.db', ro, NOOP, shared=shared)
207+
self.defs_cache['K'] = BsdDB(dir + '/definitions-cache-K.db', ro, NOOP, shared=shared)
208+
self.defs_cache['D'] = BsdDB(dir + '/definitions-cache-D.db', ro, NOOP, shared=shared)
209+
self.defs_cache['M'] = BsdDB(dir + '/definitions-cache-M.db', ro, NOOP, shared=shared)
204210
self.refs = BsdDB(dir + '/references.db', ro, RefList, shared=shared)
205211
self.docs = BsdDB(dir + '/doccomments.db', ro, RefList, shared=shared)
206212
self.dtscomp = dtscomp
@@ -216,6 +222,10 @@ def close(self):
216222
self.file.close()
217223
self.vers.close()
218224
self.defs.close()
225+
self.defs_cache['C'].close()
226+
self.defs_cache['K'].close()
227+
self.defs_cache['D'].close()
228+
self.defs_cache['M'].close()
219229
self.refs.close()
220230
self.docs.close()
221231
if self.dtscomp:

elixir/query.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,9 +188,7 @@ def query(self, cmd, *args):
188188
for tok in tokens:
189189
even = not even
190190
tok2 = prefix + tok
191-
if (even and self.db.defs.exists(tok2) and
192-
(lib.compatibleFamily(self.db.defs.get(tok2).get_families(), family) or
193-
lib.compatibleMacro(self.db.defs.get(tok2).get_macros(), family))):
191+
if even and self.db.defs_cache[family].exists(tok2):
194192
tok = b'\033[31m' + tok2 + b'\033[0m'
195193
else:
196194
tok = lib.unescape(tok)

update.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,15 @@ def update_versions(self, tag):
189189
db.vers.put(tag, obj, sync=True)
190190

191191

192+
def generate_defs_caches():
193+
for key in db.defs.get_keys():
194+
value = db.defs.get(key)
195+
for family in ['C', 'K', 'D', 'M']:
196+
if (lib.compatibleFamily(value.get_families(), family) or
197+
lib.compatibleMacro(value.get_macros(), family)):
198+
db.defs_cache[family].put(key, b'')
199+
200+
192201
class UpdateDefs(Thread):
193202
def __init__(self, start, inc):
194203
Thread.__init__(self, name="UpdateDefsElixir")
@@ -256,6 +265,8 @@ def update_definitions(self, idxes):
256265
print(f"def {type} {ident} in #{idx} @ {line}")
257266
db.defs.put(ident, obj)
258267

268+
generate_defs_caches()
269+
259270

260271
class UpdateRefs(Thread):
261272
def __init__(self, start, inc):
@@ -586,6 +597,9 @@ def progress(msg, current):
586597
print(project + ' - found ' + str(num_tags) + ' new tags')
587598

588599
if not num_tags:
600+
# Backward-compatibility: generate defs caches if they are empty.
601+
if db.defs_cache['C'].db.stat()['nkeys'] == 0:
602+
generate_defs_caches()
589603
exit(0)
590604

591605
threads_list.append(UpdateIds(tag_buf))

0 commit comments

Comments
 (0)