Repository navigation
AIML-303 Part 5: Cache ContrastSDK instance instead of creating new for each call - #55
Merged
Merged
Conversation
ChrisEdwards
marked this pull request as ready for review
December 24, 2025 08:54
ChrisEdwards
force-pushed
the
AIML-303-6-cache-sdk-instance
branch
from
January 2, 2026 17:04
c9c8250 to
7315bdd
Compare
JacobMagesHaskinsContrast
approved these changes
Jan 5, 2026
| sdkInstance = | ||
| SDKHelper.getSDK(hostName, apiKey, serviceKey, userName, httpProxyHost, httpProxyPort); | ||
| } | ||
| return sdkInstance; |
Collaborator
There was a problem hiding this comment.
Nice caching!
ChrisEdwards
force-pushed
the
AIML-303-4-cleanup
branch
from
January 6, 2026 17:22
a812ff5 to
881b53f
Compare
ChrisEdwards
force-pushed
the
AIML-303-6-cache-sdk-instance
branch
from
January 6, 2026 17:24
7315bdd to
53f3b17
Compare
dougj-contrast
approved these changes
Jan 6, 2026
ChrisEdwards
force-pushed
the
AIML-303-4-cleanup
branch
from
January 7, 2026 00:11
881b53f to
fa9943f
Compare
The SDK is stateless and thread-safe (creates new HttpURLConnection per request), so caching a single instance avoids unnecessary object creation overhead. Uses synchronized lazy initialization. - Renamed createSDK() to getSDK() to reflect caching behavior - Added test to verify caching works (same instance returned on subsequent calls) - Updated all tool test mocks to use getSDK()
ChrisEdwards
force-pushed
the
AIML-303-6-cache-sdk-instance
branch
from
January 7, 2026 00:12
53f3b17 to
b1cfc25
Compare
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR is stacked on branch
AIML-303-5-review-fixes. Review in sequence.Summary
Why
The
createSDK()method was creating a newContrastSDKinstance for every MCP tool call. Since the SDK is stateless and thread-safe (creates newHttpURLConnectionper request), a single cached instance is sufficient.What Changed
sdkInstancefield with synchronized lazy initializationcreateSDK()→getSDK()to reflect caching behaviorconfig.getSDK()createSDK()togetSDK()Thread-Safety Analysis
ContrastSDK is safe to share because:
apiKey,serviceKey,urlBuilder,gson, etc.)makeConnection()creates a newHttpURLConnectionper requestTesting
getSDK_should_cache_instance_and_return_same_on_subsequent_calls()Source
PR #45 review comment - @JacobMagesHaskinsContrast