perf: Analyze rules before running to limit context [DHIS2-21245]#181
perf: Analyze rules before running to limit context [DHIS2-21245]#181enricocolasante merged 6 commits intomasterfrom
Conversation
e4ea99c to
e8c9f9f
Compare
356a511 to
aa96488
Compare
aa96488 to
1d53a2f
Compare
vgarciabnz
left a comment
There was a problem hiding this comment.
Good! This was a missing piece in the rule engine API.
The performance benefit is on the context gathering part, isn't it? So if a client doesn't fetch the requirements in the first place and just uses the rule engine as before, the rule engine will continue to keep working as usual but there wouldn't be performance improvement, is it right? So this is an "optional" feature, it is not directly breaking the clients, right?
| val orgUnitGroups: Set<String> = emptySet(), | ||
| ) { | ||
| companion object { | ||
| val NONE = RuleContextRequirements() |
There was a problem hiding this comment.
Maybe you want to add an annotation here to avoid having to write RuleContextRequirements.Companion.getNONE() in Java.
I think that you could get:
- with
@JvmStatic->RuleContextRequirements.getNONE() - with
@JvmField->RuleContextRequirements.NONE
There was a problem hiding this comment.
I actually changed it to internal.
This object is only used as a response and shouldn't really be created in the client.
Yes, this feature is optional and it is not breaking the client. |
superskip
left a comment
There was a problem hiding this comment.
I had a brief look and have a couple of questions: First, is it primarily the backend that is going to make use of this? I can see Capture web app potentially being able to skip some of the conversion steps with this, but probably not any api calls (as we don't make any of those within the rule engine).
The second question is about a technical detail, please see comment below 👇
0f9b916 to
4c290c9
Compare
4c290c9 to
d4eceaa
Compare
| package org.hisp.dhis.rules | ||
|
|
||
| @JsExport | ||
| data class RuleContextRequirementsJs( |
There was a problem hiding this comment.
This data class could be shared (JS+JVM), unless you prefer to leave it separately just in case we want to add something here that is not compatible with JVM.
There was a problem hiding this comment.
You are right. It was in here before because we had an Array
379f78d
|



Summary
Adds a static analysis pass (
RuleEngineAnalyzer) that inspects program rules and their variables before evaluation to determine the minimum context data required. The result is surfaced as a newRuleContextRequirementsvalue object in the public API, giving callers (e.g. dhis2-core) enough information to skip fetching data they don't need.Jira: DHIS2-21245
Changes
New API
RuleContextRequirements— immutable data class (inapi/package) with fivefields:
needsAllEvents— true when the ruleset references multi-event variables (RuleVariableNewestEvent,RuleVariableNewestStageEvent,RuleVariablePreviousEvent) or theV{event_count}env var.needsEnrollment— true when enrollment env vars (enrollment_date,enrollment_id,enrollment_count,enrollment_status,incident_date,tei_count) or TEI attributes are referenced.needsDataValues— true when any event data-value variable type is referenced.needsAttributes— true whenRuleVariableAttributeis referenced.orgUnitGroups— set of group UIDs appearing ind2:inOrgUnitGroup()calls across all rule conditions and action data expressions.RuleEngine.analyzeContextRequirements(rules, variables): RuleContextRequirements— new method on the public interface, delegating toRuleEngineAnalyzer.RuleContextRequirementsJs+RuleEngineJs.analyzeContextRequirements(…)— JS wrapper exposing the same feature to the JS target (usesArray<String>fororgUnitGroupsas required by@JsExport).Housekeeping
RuleEngineUtilsconstants sorted alphabetically.isAllowedActionremoved fromRuleEventUtils(logic already inlined inRule).3.7.2-SNAPSHOT→3.8.0-SNAPSHOT(breaking interface change).expressionParserdependency bumped1.4.0→1.4.1(providescollectInOrgUnitGroupsonExpression).