Skip to content

Reduce repeated Need-graph lookups when rereading report templates #1078

Open

Description

@AlexanderLanin

What

Rereading seven report pages after Sphinx merges the parallel reader environments took about 14 seconds in Reference Integration. The report templates do this second pass so their tables can see Needs and links from other documents.

Technical approach

Profile _reread_post_template_pages and _LinkedNeeds._resolve_backlinks in src/extensions/score_sphinx_needs_templates/__init__.py. The current helper can scan all Needs for each backlink lookup and copy the graph to overlay temporarily removed Needs. Test a reverse-link index for the reread pass and an overlay that avoids copying the full mapping. Preserve live updates during document replacement, backlink order, version-qualified IDs and duplicate handling.

Measurement and reproduction dump

The env-updated hook _reread_post_template_pages took 13.905 s with 36,806 Needs in a local build of Reference Integration #501 using docs-as-code v9.0.0. The seven pages use templates marked score: render-after-needs-collection. The marked templates are module_verification_report, platform_verification_report and tool_qualification_report.

_get_available_needs() combines the current graph with the snapshot of Needs cleared for rereading. _resolve_backlinks() merges pre-existing backlinks with outgoing links from the live collection because some links have been injected and the upstream backlink index can still be incomplete. Any index needs to reflect that same view, including changes from earlier pages in the reread.

In the same phase trace, test import took 16.146 s, source/test link injection 5.680 s and bundle metadata 0.070 s. The 13.905 s number measures the whole reread callback. The proposed lookup changes have not been benchmarked. Compare with instrumented handler timings and existing report output fixtures, including mounted cross-document reports.

Related performance measurements and CI context are in #1075.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    performance

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions