Skip to content

Pre-Optimize lookups by caching model once #91

Description

@garyvidal

It appears that when you use domain:get-model-field across invokes, the caching never is used and results in expensive traversal because of // path expression which must visit every node matching the path and the predicate. The idea is to precache the entire model once and use a map:lookup which will significantly improve performance when multiple calls are made to cached functions.

A list of functions that can take advantage of pre-optimized caching
domain:get-model-unique-constraint-fields
domain:get-model-uniqueKey-constraint-fields
domain:get-model-key-field
domain:get-model-keyLabel-field
domain:get-model-identity-field
domain:get-model-field

An example of precaching is as follows:
declare function domain:precache-model($model as element(domain:model)) {
let $model-name := $model/@name
return
$model//(domain:element|domain:attribute|domain:container) ! (
domain:set-identity-cache(fn:concat($model-name || ":field:" || ./@name),.),
domain:set-identity-cache(fn:concat($model-name || ":field:" || ./@keyname),.),
domain:set-identity-cache(fn:concat($model-name || ":field:" || ./@key),.)
)
};

Activity

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions