-
Notifications
You must be signed in to change notification settings - Fork 3
β‘ Bolt: Optimize Dictionary Lookups in Semantic Registry #375
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -344,33 +344,26 @@ def _get_direct_connections_by_source( | |
| """Get DirectConnections by their source Thing name across all languages.""" | ||
| if language: | ||
| yield from self.direct_connections[language].get(source, []) | ||
| yield from ( | ||
| next( | ||
| ( | ||
| conns | ||
| for content in self._direct_connections.values() | ||
| for con_name, conns in content.items() | ||
| if con_name == source | ||
| ), | ||
| [], | ||
| ) | ||
| ) | ||
| return | ||
|
Comment on lines
345
to
+347
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. question (bug_risk): Early return when Previously, when |
||
|
|
||
| # Optimization: Early return via direct lookup avoids O(N^2) generator overhead | ||
| for content in self._direct_connections.values(): | ||
| if source in content: | ||
| yield from content[source] | ||
| break | ||
|
Comment on lines
+349
to
+353
|
||
|
|
||
| def _get_positional_connections_by_source( | ||
| self, source: ThingNameT, *, language: SemanticSearchLanguage | None = None | ||
| ) -> PositionalConnections | None: | ||
| """Get PositionalConnectionss by their source Thing name across all languages.""" | ||
|
|
||
| if language: | ||
| return self.positional_connections[language].get(source) | ||
| return next( | ||
| ( | ||
| conn | ||
| for content in self._positional_connections.values() | ||
| for con_name, conn in content.items() | ||
| if con_name == source | ||
| ), | ||
| None, | ||
| ) | ||
|
|
||
| # Optimization: Early return via direct lookup avoids O(N^2) generator overhead | ||
| for content in self._positional_connections.values(): | ||
| if source in content: | ||
| return content[source] | ||
| return None | ||
|
Comment on lines
+362
to
+366
|
||
|
|
||
| def get_positional_connections_by_source( | ||
| self, source: ThingNameT, *, language: SemanticSearchLanguage | None = None | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion (typo): Consider using the term "generator expressions" instead of "generator comprehensions" for Python accuracy.
To match standard Python terminology and avoid confusion, please rename the section and Action line to use βgenerator expressionsβ instead of βgenerator comprehensions.β
Suggested implementation: