Skip to content

Prefetch research: batch relation-target loads (wake-free via five.intid keyref oids) #4353

Description

@jensens

Part of the research plan for #4350 (see anchor comment there for the full decomposition).

Relations are the highest-confidence track: the target oid is derivable without waking the target (intids.refs[to_id].oid, stored as a plain attribute by five.intid, five/intid/keyreference.py:103, five.intid 3.1.0), and production numbers in #4350 already show the win for tiles/logos rendered from relations.

Resolution chain (why every access is a load)

RelationValue.to_objectz3c/relationfield/relation.py:50,123-133 (z3c.relationfield 3.1) → intids.getObject(id)zope/intid/__init__.py:92-98 (zope.intid 6.0): self.refs[id]() = one object load per access. to_path, to_interfaces, and notably RelationValue.__lt__ (relation.py:84-95) all go through to_objectsorting a relation list loads every target.

Call sites found (Plone 6.2 coredev scan, 2026-07-06)

# Call site Pattern
A1 plone.app.layout 6.0.1 viewlets/content.py:336-355 related-items viewlet r.to_path per relation
A2 plone.restapi 10.0.1 serializer/relationfield.py:49 [el for el in value if el.to_object]
A3 plone.restapi services/relations/get.py:97-135 from_object/to_object per relation
A4 plone.app.relationfield 5.0.0 widget.py:125-131,162-168 data managers rel.to_object per item
A5 plone.api relation.py:111-133, 291-329 from_object/to_object per relation
A6 Products.CMFPlone relationhelper.py:62-73, 77-119 resolveRelationToken per token (stats/rebuild)
A7 zc.relation 3.0 catalog.py:734-736 + z3c.relationfield index.py:46-50 resolveRelationTokens generator — one intids.getObject per token
A8 plone.app.linkintegrity utils.py:11-43 callers back-relations, .from_object per hit

Tasks

  • Apply the plone.base helper (sibling sub-issue) in measured-impact order: related-items viewlet (A1), restapi relation serializer + @relations service (A2, A3), widgets (A4).
  • Evaluate the generic fix: teach resolveRelationTokens-driven paths to prefetch a token window (A7) — that transparently covers A5, A6, A8. Needs upstream buy-in in zc.relation / z3c.relationfield; fallback is call-site helpers in the Plone packages only.
  • Check whether relation-list sorting paths (via __lt__) can sort on to_path-from-catalog or prefetch first.
  • Before/after numbers from the measurement harness sub-issue for each change.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions