From c1c2771a5ed5ce1b9ad605dd1834616905c2f190 Mon Sep 17 00:00:00 2001 From: William Chargin Date: Tue, 30 Jul 2019 16:30:06 -0700 Subject: [PATCH] backend: eliminate unnecessary metaprogramming (#2478) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Summary: This was a relic of a piecewise migration from the `event_accumulator`’s old form to its current `plugin_event_accumulator` form. (See #345 for an example of one of the intermediate states.) Now totally superfluous, it incurs needless cognitive and CPU overhead, as the `getattr` blocks standard optimizations. Test Plan: All tests pass, and TensorBoard can still load the standard demo data. wchargin-branch: eliminate-metaprogramming --- .../plugin_event_accumulator.py | 22 +++++++------------ 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/tensorboard/backend/event_processing/plugin_event_accumulator.py b/tensorboard/backend/event_processing/plugin_event_accumulator.py index 27400a21edc..902bb8587ba 100644 --- a/tensorboard/backend/event_processing/plugin_event_accumulator.py +++ b/tensorboard/backend/event_processing/plugin_event_accumulator.py @@ -43,11 +43,6 @@ TensorEvent = namedtuple('TensorEvent', ['wall_time', 'step', 'tensor_proto']) -## Different types of summary events handled by the event_accumulator -SUMMARY_TYPES = { - 'tensor': '_ProcessTensor', -} - ## The tagTypes below are just arbitrary strings chosen to pass the type ## information of the tag from the backend to the frontend TENSORS = 'tensors' @@ -350,15 +345,14 @@ def _ProcessEvent(self, event): ('This summary with tag %r is oddly not associated with a ' 'plugin.'), tag) - for summary_type, summary_func in SUMMARY_TYPES.items(): - if value.HasField(summary_type): - datum = getattr(value, summary_type) - tag = value.tag - if summary_type == 'tensor' and not tag: - # This tensor summary was created using the old method that used - # plugin assets. We must still continue to support it. - tag = value.node_name - getattr(self, summary_func)(tag, event.wall_time, event.step, datum) + if value.HasField('tensor'): + datum = value.tensor + tag = value.tag + if not tag: + # This tensor summary was created using the old method that used + # plugin assets. We must still continue to support it. + tag = value.node_name + self._ProcessTensor(tag, event.wall_time, event.step, datum) def Tags(self): """Return all tags found in the value stream.