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

PackageNotFoundException is instanciated a lot and quite costly #36

Closed
pcdavid opened this issue May 29, 2024 · 2 comments · Fixed by #40
Closed

PackageNotFoundException is instanciated a lot and quite costly #36

pcdavid opened this issue May 29, 2024 · 2 comments · Fixed by #40
Assignees

Comments

@pcdavid
Copy link
Member

pcdavid commented May 29, 2024

In org.eclipse.sirius.emfjson.utils.GsonEObjectDeserializer.deserializeMultipleNonContainmentEReference (among others) we try to resolve the resource part of a reference URI as an EPackage using getPackageForURI(String uriString).

This works for the case where the reference URI is of the form e.g. http://www.eclipse.org/emf/2002/Ecore#//EBoolean, but will fail in most concrete cases where the reference URI will be something like 52317c1f-0516-48b4-bad4-15a3a07aebe9#//path/to/some/element.1. In such a case getPackageForURI keeps track of the error with:

this.helper.getResource().getErrors().add(new PackageNotFoundException(uriString, this.helper.getResourceURI().toString()));

Unfortunately, the error type used, PackageNotFoundException is an actual Java exception, which is very costly to create (because of fillStackTrace). I'm not sure why this Resource.Diagnostic (along with all the other JsonException subtypes) are exceptions, but just commenting out this line to avoid creating thousands of exceptions when loading a medium-sized model give a significant performance boost:

Before (master, emf-json 2.3.9/master):

  • EditingContext loaded in 2750ms
  • EditingContext loaded in 1989ms
  • EditingContext loaded in 2179ms
  • EditingContext loaded in 2032ms
  • EditingContext loaded in 2210ms
  • EditingContext loaded in 2303ms
  • EditingContext loaded in 1892ms
  • Average: 2193ms

After (commented this.helper.getResource().getErrors().add(new PackageNotFoundException()))

  • EditingContext loaded in 1746ms
  • EditingContext loaded in 1674ms
  • EditingContext loaded in 1663ms
  • EditingContext loaded in 1686ms
  • EditingContext loaded in 1697ms
  • EditingContext loaded in 1682ms
  • Average: 1691ms

Simply commenting out the code is probably too much, but replacing an exception with a plain Resource.Diagnostic object should get us most of the gain (I need to confirm).

@pcdavid pcdavid self-assigned this Jun 4, 2024
@pcdavid
Copy link
Member Author

pcdavid commented Jun 4, 2024

Here's a measure of the time just building the PacakgeNotFoundException instances when loading the "Sirius Web" Papaya example:

image

@pcdavid
Copy link
Member Author

pcdavid commented Jun 4, 2024

After switching to a plain class implementing EMF's Resource.Diagnostic directly, it's still invoked 20k times but but now accounts for ~1ms in total:

image

(I had to switch to YourKit's tracing mode, as in sampling mode it's not even measurable).

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 a pull request may close this issue.

1 participant