Skip to content

perf: Replace Reflections with ClassGraph and share scan across factories (TEDEFO-5033)#53

Merged
rousso merged 1 commit intodevelopfrom
TEDEFO-3329-improve-component-loading
Apr 28, 2026
Merged

perf: Replace Reflections with ClassGraph and share scan across factories (TEDEFO-5033)#53
rousso merged 1 commit intodevelopfrom
TEDEFO-3329-improve-component-loading

Conversation

@rousso
Copy link
Copy Markdown
Contributor

@rousso rousso commented Apr 28, 2026

Summary

Eliminates the slow Reflections classpath scan that made the EFX validator (and any other consumer of SdkComponentFactory) prohibitively slow when run from a Spring Boot fat JAR (mdm-cli, mdm-war).

Two changes in SdkComponentFactory:

  1. Reflections → ClassGraph. Modern, actively maintained, native support for Spring Boot fat JARs, ASM-based bytecode reading. .ignoreClassVisibility() preserves the previous behaviour of finding non-public @SdkComponent classes.
  2. Cross-factory scan dedup. Hoist the scan to a static AnnotatedClassesHolder whose result is shared across all SdkComponentFactory subclasses (today: SdkEntityFactory, ComponentFactory, EfxTranslatorFactory). Three independent scans → one.

Measured impact (mdm-cli analyse-sdk --efx against eForms-SDK)

Before After
Number of scans per JVM 3 1
Total classpath scan time 43 s (3 × ~14 s) 2.8 s
Per-scan duration 13–15 s 2.8 s

Public API unchanged. Subclass constructors are unaffected.

Side effect: TEDEFO-3328

The Reflections configuration relied on ClassLoader.getDefinedPackages(), which only returns packages whose classes have already been initialised — the root cause of TEDEFO-3328 (components in a not-yet-touched JAR being missed). ClassGraph scans by classpath URL, so this trap is gone. We can likely close TEDEFO-3328 alongside this change.

What is NOT addressed

The remaining analyse-sdk --efx runtime (~9 minutes for SDK 2.0) is dominated by per-template translation work inside EfxTemplateTranslator.renderTemplate(), not by classpath scanning. That is a separate optimisation problem in efx-toolkit-java and is being investigated separately.

Test plan

  • All 67 eforms-core-java tests pass
  • All 1335 efx-toolkit-java tests pass against the new eforms-core-java SNAPSHOT
  • All 161 eforms-sdk-analyzer tests pass against the chain
  • mdm-cli analyse-sdk --efx against eForms-SDK 2.0 source: same 158 errors found before and after the change (correctness preserved)

@rousso rousso requested a review from rouschr April 28, 2026 14:25
Copy link
Copy Markdown
Contributor

@rouschr rouschr left a comment

Choose a reason for hiding this comment

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

Looks like a useful improvement, less brute force than before.

@rousso rousso merged commit 2864088 into develop Apr 28, 2026
5 checks passed
@rousso rousso deleted the TEDEFO-3329-improve-component-loading branch April 28, 2026 14: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.

2 participants