Skip to content

Comments

Optimize ThingEventEnricher -> TreeBasedPolicyEnforcer hot path#2344

Open
thjaeckle wants to merge 1 commit intoeclipse-ditto:masterfrom
beyonnex-io:optimize/tree-based-policy-enforcer-hot-path
Open

Optimize ThingEventEnricher -> TreeBasedPolicyEnforcer hot path#2344
thjaeckle wants to merge 1 commit intoeclipse-ditto:masterfrom
beyonnex-io:optimize/tree-based-policy-enforcer-hot-path

Conversation

@thjaeckle
Copy link
Member

@thjaeckle thjaeckle commented Feb 17, 2026

Reduce redundant policy tree walks and thing.toJson() serializations in the per-ThingEvent enrichment path, which JFR profiling identified as the No. 1 CPU hotspot on production things nodes.

  • Add ClassifySubjectsVisitor that replaces 3 separate tree walks (partial/unrestricted/effected) with a single pass, returning a SubjectClassification result. Expose as classifySubjects() on the Enforcer interface with an optimized override in TreeBasedPolicyEnforcer.

  • Add batch getAccessiblePathsForSubjects() that flattens Thing JSON into leaf pointers once per batch instead of once per subject. Default method on Enforcer with an optimized override in TreeBasedPolicyEnforcer.

  • Cache thing.toJson() once at the top of enrichWithPredefinedExtraFields() and thread the JsonObject through ReadGrantCollector, PartialAccessPathCalculator, and the extra fields header builder, eliminating redundant serializations per event.

  • Extract ROOT_RESOURCE_POINTER constant in TreeBasedPolicyEnforcer to avoid repeated JsonFactory.newPointer("/") allocations.

@thjaeckle thjaeckle added this to the 3.9.0 milestone Feb 17, 2026
Reduce redundant policy tree walks and thing.toJson() serializations
in the per-ThingEvent enrichment path, which JFR profiling identified
as the eclipse-ditto#1 CPU hotspot on production things nodes.

- Add ClassifySubjectsVisitor that replaces 3 separate tree walks
  (partial/unrestricted/effected) with a single pass, returning a
  SubjectClassification result. Expose as classifySubjects() on the
  Enforcer interface with an optimized override in
  TreeBasedPolicyEnforcer.

- Add batch getAccessiblePathsForSubjects() that flattens Thing JSON
  into leaf pointers once per batch instead of once per subject.
  Default method on Enforcer with an optimized override in
  TreeBasedPolicyEnforcer.

- Cache thing.toJson() once at the top of
  enrichWithPredefinedExtraFields() and thread the JsonObject through
  ReadGrantCollector, PartialAccessPathCalculator, and the extra
  fields header builder, eliminating redundant serializations per
  event.

- Extract ROOT_RESOURCE_POINTER constant in TreeBasedPolicyEnforcer
  to avoid repeated JsonFactory.newPointer("/") allocations.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Signed-off-by: Thomas Jäckle <thomas.jaeckle@beyonnex.io>
@thjaeckle thjaeckle force-pushed the optimize/tree-based-policy-enforcer-hot-path branch from 5d37b6b to 459a8cf Compare February 17, 2026 16:14
@thjaeckle thjaeckle self-assigned this Feb 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

1 participant