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

refactor: optimize dependency graph performances #4587

Merged
merged 1 commit into from
Oct 28, 2024

Conversation

ndr-brt
Copy link
Member

@ndr-brt ndr-brt commented Oct 28, 2024

What this PR changes/adds

Does some little tweaks to DependencyGraph to improve performance, both time and memory wise.

The code used to measure the improvements has been put on ExtensionLoader in the loadServiceExtensions method:

Runtime runtime = Runtime.getRuntime();
var memoryUsed = runtime.totalMemory() - runtime.freeMemory();
System.out.println("USED MEMORY BEFORE: " + memoryUsed);
var l = System.currentTimeMillis();
System.out.println("CREATE DEPENDENCY GRAPH STARTED AT " + l);
var injectionContainers = new DependencyGraph(context).of(serviceExtensions);
System.out.println("DEPENDENCY GRAPH CREATED IN " + (System.currentTimeMillis() - l));
System.out.println("USED MEMORY BY DEP GRAPH: " + ((runtime.totalMemory() - runtime.freeMemory()) - memoryUsed));

With the changes put in place (details in the "further notes" section) I observed, measuring 10 times and extracting the mean value:

  • execution time lowered by ≈ 20% (from 62,4ms to 48,1ms)
  • memory used lowered by ≈ 5% (from 7.92Mb to 7.46Mb)

these improvements don't look really game changing, but they will be definitely helpful in multiple-connectors environment, plus it's always good to apply good code practices (see below)

Why it does that

startup performances

Further notes

The improvements evolve around:

  • less loops on extensions: removed 2 unnecessary iterations
  • avoid collection of streams if not really needed
  • build injectionPoints sets to be put in injection containers directly when they are evaluated first, this is avoiding instantiation of N (number of extensions) streams and filter of the whole set of injection points.
  • moved ReflectiveObjectFactory into junit module as it's only used in test context.

Linked Issue(s)

Closes # <-- insert Issue number if one exists

Please be sure to take a look at the contributing guidelines and our etiquette for pull requests.

@ndr-brt ndr-brt added the refactoring Cleaning up code and dependencies label Oct 28, 2024
@ndr-brt ndr-brt requested a review from wolf4ood October 28, 2024 10:02
@ndr-brt ndr-brt force-pushed the optimize-dependency-graph branch from 4400827 to 98c50c5 Compare October 28, 2024 10:14
@ndr-brt ndr-brt marked this pull request as ready for review October 28, 2024 10:14
@ndr-brt ndr-brt force-pushed the optimize-dependency-graph branch from 98c50c5 to 0a26dbc Compare October 28, 2024 12:45
@ndr-brt ndr-brt merged commit e6b6560 into eclipse-edc:main Oct 28, 2024
21 checks passed
@ndr-brt ndr-brt deleted the optimize-dependency-graph branch October 28, 2024 15:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
refactoring Cleaning up code and dependencies
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants