-
-
Notifications
You must be signed in to change notification settings - Fork 81
Cast message to MessageType before creating StreamChunk in stream_broadcaster #311
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
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 | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -268,7 +268,8 @@ def _stream_define_callback_wrapper_proc(callback_name, method_proc) | |||||||
| # @return [Proc] callback proc that accepts (message, delta, type) | ||||||||
| def stream_broadcaster | ||||||||
| proc do |message, delta, type| | ||||||||
| self.stream_chunk = StreamChunk.new(message, delta) | ||||||||
| cast_message = message.is_a?(Hash) ? Providers::Common::Messages::Types::MessageType.new.cast(message) : message | ||||||||
| self.stream_chunk = StreamChunk.new(cast_message, delta) | ||||||||
|
Comment on lines
+271
to
+272
|
||||||||
| cast_message = message.is_a?(Hash) ? Providers::Common::Messages::Types::MessageType.new.cast(message) : message | |
| self.stream_chunk = StreamChunk.new(cast_message, delta) | |
| self.stream_chunk = StreamChunk.new(message, delta) |
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.
Providers::Common::Messages::Types::MessageType.newis instantiated for every streamed chunk. Sincestream_broadcastermay be called many times per request, this creates avoidable allocations; consider memoizing the MessageType instance (e.g., build it once perstream_broadcastercall and close over it, or store it in an ivar) and reuse it for each cast.