Skip to content

Improve efficiency of getattr(tm, scale), particularly access to jd1/jd2 #4309

@taldcroft

Description

@taldcroft

When accessing an arbitrary time scale for a Time object, the internal object is always replicated. This came up in #4302.

    def __getattr__(self, attr):
        """
        Get dynamic attributes to output format or do timescale conversion.
        """
        if attr in self.SCALES and self.scale is not None:
            tm = self.replicate()
            tm._set_scale(attr)
            return tm

What about:

  • Return self if attr == self.scale?
  • Cache other scales so getting both jd1 and jd2 after transforming will be efficient?
    Roughly:
    def __getattr__(self, attr):
        """
        Get dynamic attributes to output format or do timescale conversion.
        """
        if attr in self.SCALES and self.scale is not None:
            if attr == self.scale:
                tm = self
            elif attr in self._scale_cache:
                tm = self._scale_cache[attr]
            else:
                tm = self.replicate()
                tm._set_scale(attr)
                self._scale_cache[attr] = tm
            return tm

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions