forked from microsoft/semantic-kernel
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix concurrency issues and double lookups in SkillCollection (microso…
…ft#603) ### Motivation and Context Fix concurrency issues in SkillCollection and reduce overhead and duplication. ### Description If multiple threads concurrently call AddSemantic/NativeFunction, and the skill in question didn't yet exist, both threads could try to add a new collection for that skill. But they're doing so with the indexer, which means one of them could overwrite the one added by the other, which could already have progressed to store the target function into that collection. At that point, data could be lost. By using TryAdd instead of the indexer, we can avoid such overwrites, and by using GetOrAdd, we can simplify the whole pattern. Further, throughout the SkillCollection, there are places where we're looking up into dictionaries twice, first to do a ContainsKey and then subsequently to get the value for that key; better to just use TryGetValue to do the lookup once. There was also duplication between routines for semantic and native functions, which could be collapsed with single helpers.
- Loading branch information
1 parent
b7573a9
commit 2242ab8
Showing
16 changed files
with
237 additions
and
261 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
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
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
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
Oops, something went wrong.