Skip to content

Add TreeSequence.node_time, node_population and node_flags arrays #1917

Closed

Description

@jeromekelleher

As we see in #1916, calling self.tables.nodes.time can be very expensive because we are currently forced to make a copy of the whole table collection just to get access to one array. This adds up when we're working with large tables. While fixing this properly is a long term project, we can fix the worst behaviour within the library at least by adding there arrays to the TreeSequence object, following the approach used for the tree arrays in the Tree class.

The implementation would look very like

/* The x_array properties are the high-performance zero-copy interface to the

See also the Python shim:

def _make_arrays(self):

There's a question about whether we should make this interface public or not. I guess since it's a regular pain-point and we're not going to fix the read-only tables view thing any time in the immediate future, we probably should?

Does anyone want to take this on to get it into 0.4.0? @benjeffery and I are maxed out trying to get other stuff shipped I'm afraid.

Activity

  1. added
    enhancement
    Python API
    Performance
    on Nov 17, 2021
  2. benjeffery commented on Nov 17, 2021

    @benjeffery
    Member

    I wonder if we make this generic for all arrays, something like TreeSequence.arrays.nodes.time?

  3. benjeffery commented on Nov 17, 2021

    @benjeffery
    Member

    Depends on if you see this as a short term fix or not I guess.

  4. jeromekelleher commented on Nov 17, 2021

    @jeromekelleher
    MemberAuthor

    Depends on whether there's any advantage ultimately to this vs TreeSequence.tables.nodes.time? I don't think there would be if we cached a reference to the TableCollection object, and it was in turn a read-only view on the underlying TreeSequence tables?

    In that case it seem like a lot of work to take on and potentially quite confusing for users. This isn't the only reason we'd want to have a read-only copy of the tables in the tree sequence, since it would allow us to avoid a copy at load time too.

  5. petrelharp commented on Nov 17, 2021

    @petrelharp
    Contributor

    I'm not sure if this is worth it: right now, we can save out the tables once and referring to them (so, only 2x the memory). The worst of what happened in #1916 was because of mulitple calls to ts.tables.nodes.time.

  6. jeromekelleher commented on Nov 17, 2021

    @jeromekelleher
    MemberAuthor

    We still have a few library functions that use ts.tables.nodes.time though (#1916) - we'd like those to not use huge amounts of RAM and take way longer than they should. If we don't document these arrays then it's not much work to make a big difference for #1916

  7. added 4 commits that reference this issue on Jul 21, 2022
    c106abe
    d655c44
    4e863d8
    01ef912
  8. added a commit that references this issue on Mar 22, 2024
    ada9596
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    PerformancePython APIenhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions