-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #243 from Sanne/Performance
Micro performance improvements
- Loading branch information
Showing
7 changed files
with
336 additions
and
238 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
415 changes: 226 additions & 189 deletions
415
cdi/src/main/java/io/smallrye/context/cdi/context/propagation/CdiContextProvider.java
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 3 additions & 18 deletions
21
core/src/main/java/io/smallrye/context/impl/CapturedContextState.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 44 additions & 3 deletions
47
core/src/main/java/io/smallrye/context/impl/ThreadContextProviderPlan.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,60 @@ | ||
package io.smallrye.context.impl; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Set; | ||
|
||
import org.eclipse.microprofile.context.spi.ThreadContextProvider; | ||
import org.eclipse.microprofile.context.spi.ThreadContextSnapshot; | ||
|
||
public class ThreadContextProviderPlan { | ||
|
||
public final Set<ThreadContextProvider> propagatedProviders; | ||
public final Set<ThreadContextProvider> unchangedProviders; | ||
public final Set<ThreadContextProvider> clearedProviders; | ||
|
||
/** | ||
* Following 3 fields are meant to optimise method #takeThreadContextSnapshots | ||
* which is extremely hot at runtime, at cost of little extra memory for this plan. | ||
*/ | ||
private final int snapshotInitialSize; | ||
private final ThreadContextProvider[] propagatedProvidersFastIterable; | ||
private final ThreadContextProvider[] clearedProvidersFastIterable; | ||
|
||
public ThreadContextProviderPlan(Set<ThreadContextProvider> propagatedSet, Set<ThreadContextProvider> unchangedSet, | ||
Set<ThreadContextProvider> clearedSet) { | ||
this.propagatedProviders = propagatedSet; | ||
this.unchangedProviders = unchangedSet; | ||
this.clearedProviders = clearedSet; | ||
this.propagatedProviders = Collections.unmodifiableSet(propagatedSet); | ||
this.unchangedProviders = Collections.unmodifiableSet(unchangedSet); | ||
this.clearedProviders = Collections.unmodifiableSet(clearedSet); | ||
this.snapshotInitialSize = propagatedProviders.size() + clearedProviders.size(); | ||
this.propagatedProvidersFastIterable = propagatedProviders.toArray(new ThreadContextProvider[0]); | ||
this.clearedProvidersFastIterable = clearedProviders.toArray(new ThreadContextProvider[0]); | ||
} | ||
|
||
/** | ||
* This helps to optimise construction of CapturedContextState | ||
* without exposing too many implementation details. | ||
* Only useful for snapshots with an empty property set. | ||
* | ||
* @return a list of snapshots | ||
*/ | ||
public List<ThreadContextSnapshot> takeThreadContextSnapshots() { | ||
List<ThreadContextSnapshot> threadContextSnapshots = new ArrayList<>(snapshotInitialSize); | ||
final Map<String, String> props = Collections.emptyMap(); | ||
for (ThreadContextProvider provider : propagatedProvidersFastIterable) { | ||
ThreadContextSnapshot snapshot = provider.currentContext(props); | ||
if (snapshot != null) { | ||
threadContextSnapshots.add(snapshot); | ||
} | ||
} | ||
for (ThreadContextProvider provider : clearedProvidersFastIterable) { | ||
ThreadContextSnapshot snapshot = provider.clearedContext(props); | ||
if (snapshot != null) { | ||
threadContextSnapshots.add(snapshot); | ||
} | ||
} | ||
return threadContextSnapshots; | ||
} | ||
} |