From: Petr Špaček Date: Mon, 4 Jul 2022 09:01:17 +0000 (+0200) Subject: Optimize resolve_xref to avoid O(n^2) iteration X-Git-Tag: v9.19.3~13^2~2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=8a5f20121ea1fc5375fab0ba777d36a5605e3763;p=thirdparty%2Fbind9.git Optimize resolve_xref to avoid O(n^2) iteration Formerly resolve_xref() in Sphinx extension called get_objects() from Sphinx API which subsequently iterated the whole list of objects, causing single iteration per single reference, which is essentially. O(n^2). Avoid using get_objects() and access internal dictionary directly intead. The docs build time was still dominated by other factors but speedup is about 10 % on my machine. --- diff --git a/doc/arm/_ext/iscconf.py b/doc/arm/_ext/iscconf.py index 4380a8c4c1a..53eb2f946ae 100644 --- a/doc/arm/_ext/iscconf.py +++ b/doc/arm/_ext/iscconf.py @@ -305,19 +305,18 @@ def domain_factory(domainname, domainlabel, todolist, grammar): Sphinx API: Resolve the pending_xref *node* with the given typ and target. """ - match = [ - (docname, anchor) - for name, sig, typ, docname, anchor, _prio in self.get_objects() - if sig == target - ] - - if len(match) == 0: + try: + obj = self.data["statements"][self.get_statement_name(target)] + except KeyError: return None - todocname = match[0][0] - targ = match[0][1] refnode = make_refnode( - builder, fromdocname, todocname, targ, contnode, targ + builder, + fromdocname, + obj["docname"], + obj["anchor"], + contnode, + obj["anchor"], ) return refnode