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 package-to-scan feature #786

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ajacob
Copy link
Contributor

@ajacob ajacob commented May 1, 2020

Context

Some applications can have thousands of classes.
When JPA is configured to scan classes (exclude-unlisted-classes is false in persistence.xml), the time used to scan all classes can be quite long.
With reasonable application size, class scanning can take only ten's of milliseconds but for heavy application it can take a few seconds.

In order to help reducing startup time, we can restrict class scanning to a pre-configured list of known packages to avoid loading unnecessary classes metadata.

What was done

  • Introduced a new property PersistenceUnitProperties.PACKAGES_TO_SCAN: eclipselink.packages-to-scan
  • Modified PersistenceUnitProcessor.getClassNamesFromURL to only return eligible classes

This new property takes as a value a list of packages as a string: com.foo.bar, some.other.packages

Performance result

I've tested this feature with 2 applications, one with ~1000 classes and another with more than 30k classes.
MetadataProcessor.initPersistenceUnitClasses was faster by ~25% for the small application and ~45% for the big one.

NOTE: This is a port from a 2.7.4 patched version running in production

# Context

Some applications can have thousands of classes.
When JPA is configured to scan classes (`exclude-unlisted-classes` is `false` in `persistence.xml`), the time used to scan all classes can be quite long.
With reasonable application size, class scanning can take only ten's of milliseconds but for heavy application it can take a few seconds.

In order to help reducing startup time, we can restrict class scanning to a pre-configured list of known packages to avoid loading unnecessary classes metadata.

# What was done

- Introduced a new property `PersistenceUnitProperties.PACKAGES_TO_SCAN`: `eclipselink.packages-to-scan`
- Modified `PersistenceUnitProcessor.getClassNamesFromURL` to only return eligible classes

This new property takes as a value a list of packages as a string: `com.foo.bar, some.other.packages`

# Performance result

I've tested this feature with 2 applications, one with ~1000 classes and another with more than 30k classes.
`MetadataProcessor.initPersistenceUnitClasses` was faster by ~25% for the small application and ~45% for the big one.

Signed-off-by: Alexandre Jacob <alexandref.jacob@gmail.com>
@ajacob ajacob force-pushed the add-packages-to-scan-feature branch from 519a95b to 6a6dabf Compare May 1, 2020 09:26
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.

None yet

2 participants