-
Notifications
You must be signed in to change notification settings - Fork 3
⚡ Bolt: [performance improvement] optimize string length summation in config types #284
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
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 | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -134,7 +134,8 @@ class DocumentRepr: | |||||||||||||||||||||
| async def serialize_for_upsert(self, texts: list[str]) -> list[Document]: | ||||||||||||||||||||||
| """Serialize the document representations for Qdrant upsert.""" | ||||||||||||||||||||||
| await asyncio.sleep(ZERO) | ||||||||||||||||||||||
| avg_length = int(sum(len(text.strip()) for text in texts) / len(texts)) if texts else 0 | ||||||||||||||||||||||
| # Optimization: sum(map(len, map(str.strip, texts))) is significantly faster than a generator comprehension | ||||||||||||||||||||||
| avg_length = int(sum(map(len, map(str.strip, texts))) / len(texts)) if texts else 0 | ||||||||||||||||||||||
|
Comment on lines
136
to
+138
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. suggestion: The micro-optimization and use of float division may hurt readability with marginal benefit. In this async, I/O-heavy path the performance gain is probably negligible compared to the readability cost. If you keep this form, you can simplify it to avoid float math and
Suggested change
|
||||||||||||||||||||||
| options = await self.options.serialize_for_upsert(avg_length) | ||||||||||||||||||||||
| return [Document(text=text, model=self.model, options=options) for text in texts] | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
|
|
||||||||||||||||||||||
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.
The inline note says “generator comprehension”, but the previous form was a generator expression (
sum(len(text.strip()) for text in texts)). Using the correct term here will avoid confusion for readers.