You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@beam.apache.org by GitBox <gi...@apache.org> on 2021/08/23 20:45:56 UTC

[GitHub] [beam] pabloem commented on a change in pull request #15357: [BEAM-12781] Add memoization of BoundedSource encoding for SDFBoundedSourceReader

pabloem commented on a change in pull request #15357:
URL: https://github.com/apache/beam/pull/15357#discussion_r694296420



##########
File path: sdks/python/apache_beam/io/iobase.py
##########
@@ -1573,15 +1581,28 @@ def is_bounded(self):
     return True
 
 
+class _RestrictionCoder(coders.Coder):

Review comment:
       done

##########
File path: sdks/python/apache_beam/io/iobase.py
##########
@@ -886,12 +888,18 @@ def get_desired_chunk_size(total_size):
 
   def expand(self, pbegin):
     if isinstance(self.source, BoundedSource):
+      coders.registry.register_coder(BoundedSource, _MemoizingPickleCoder)
       display_data = self.source.display_data() or {}
       display_data['source'] = self.source.__class__
+
+      def output_source(_) -> BoundedSource:
+        assert isinstance(self.source, BoundedSource)

Review comment:
       removed the function. (fwiw - I had used the assert to work around mypy complaining about types)

##########
File path: sdks/python/apache_beam/coders/coders.py
##########
@@ -741,6 +742,36 @@ def __hash__(self):
     return hash(type(self))
 
 
+class _MemoizingPickleCoder(_PickleCoderBase):
+  """Coder using Python's pickle functionality with memoization."""
+  def __init__(self, cache_size=16):
+    super(_MemoizingPickleCoder, self).__init__()
+    self.cache_size = cache_size
+
+  def _create_impl(self):
+    dumps = pickle.dumps

Review comment:
       makes sense. I've put pickler in, since the current use (`BoundedSource` elements) contains code and context.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org