Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add optional argument for making clone of predefined resources #1500

Merged
merged 1 commit into from
Aug 26, 2024

Conversation

mint-thompson
Copy link
Collaborator

This PR applies to task CIMPL-1250.

The FHIRDefinitions class provides a public method to return all predefined resources. Hypothetically, the caller of this method could alter the predefined resources, which is why it could be useful to return a clone of these resources. However, in all places this method is called by SUSHI, the resources are used for a search, not for any modifications. By not cloning the resources for the search, significant time savings are possible. Just in case someone else is using SUSHI as a dependency and calling this method and expecting to receive a clone, the default behavior is to return a clone.

When searching for slices, the slice of an element is always a sibling of that element. Therefore, it is preferable to search the smaller list containing only the element's parent's children, when possible. This takes advantage of the underlying ElementDefinition tree. Because the root element's parent is undefined, use the full element list when working with the root element. This shouldn't be possible in most cases, as revealed by the test coverage, but the implementation is defensive just in case something unusual has happened to the root element.

A regression test of public FSH projects updated within the last year indicated no changes. The initial test run indicated changes in two repos, but both of those repos produced identical results in a second run without any code changes. The changes to allPredefinedResources are most visible in projects with many StructureDefinitions. The changes to ElementDefinition are most visible in projects with many Instance definitions. The impact of the ElementDefinition changes is relatively small, but the allPredefinedResources changes are significant for some FSH projects.

The regression test results summary is attached as html. Three projects showed increased run times, but all of those projects are relatively small, with the longest run time being 61 seconds. Some larger projects showed meaningful decreases in run time. As a few examples:

While these are just a few examples I've picked out, and not every project has changes that are so dramatic, I think the overall effect is meaningfully positive without adding an odious amount of complexity to the implementation.

Regression summary HTML

The FHIRDefinitions class provides a public method to return all
predefined resources. Hypothetically, the caller of this method could
alter the predefined resources, which is why it could be useful to
return a clone of these resources. However, in all places this method is
called by SUSHI, the resources are used for a search, not for any
modifications. By not cloning the resources for the search, significant
time savings are possible. Just in case someone else is using SUSHI as a
dependency and calling this method and expecting to receive a clone, the
default behavior is to return a clone.

When searching for slices, the slice of an element is always a sibling
of that element. Therefore, it is preferable to search the smaller list
containing only the element's parent's children, when possible. This
takes advantage of the underlying ElementDefinition tree. Because the
root element's parent is undefined, use the full element list when
working with the root element. This shouldn't be possible in most cases,
as revealed by the test coverage, but the implementation is defensive
just in case something unusual has happened to the root element.
Copy link
Collaborator

@jafeltra jafeltra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These changes all make sense to me! I looked through the regression from the last year, and nothing looks changed and the changes in time are honestly so impressive.

Good finds! Hopefully this helps people who were still struggling with performance!

Copy link
Member

@cmoesel cmoesel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow. What a find! Well done!

@cmoesel cmoesel merged commit e91f68e into master Aug 26, 2024
14 checks passed
@cmoesel cmoesel deleted the cimpl-1250-predefined-clone-option branch August 26, 2024 12:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants