Skip to content

Trajectories should be deque, not lists (while generating) #1099

Open

Description

@sroet

When looking over #1066 I noticed that when the engine is running backwards we are adding to the trajectory via:

trajectory.insert(0, snapshot.reversed)

This is slow, and becomes slower when the list is longer. As we are only ever appending to the trajectory on the ends, the appropriate data structure should be deque instead.
Screenshot from 2022-01-17 11-18-10

Access by index becomes slower (especially in the middle) so that might need to be handled. Ideally a trajectory would be a deque while running/generating and converting them to a list when finalizing.
Screenshot from 2022-01-17 11-32-50

Activity

  1. sroet commented on Jan 17, 2022

    @sroet
    MemberAuthor

    Here are some runs for the 1000-10_000 range (more typical for trajectories)

    1000

    Screenshot from 2022-01-17 11-37-07

    10_000

    Screenshot from 2022-01-17 11-37-58

  2. dwhswenson commented on Jan 17, 2022

    @dwhswenson
    Member

    True, but is there any reason to believe that this is a performance bottleneck in real-world use? I think that we have enough overhead in other places that we'd get better performance improvements elsewhere.

    An update for this would be welcome, but I don't think it's urgently required (so I probably won't implement it, personally).

    One note: some aspects around the DynamicsEngine.generate and DynamicsEngine.iter_generate are likely to be significantly changed in 2.0. First part of that change in #1042, but I'm also don't particularly like the way DynamicsEngine.generate does this for trajectory in it: pass thing -- it seems wasteful to create an entire new trajetory object that we just throw away over and over again (overhead of UUIDs, etc). I'm open to significant changes in that for OPS 2.0, such as returning an iterator of snapshots instead of trajectories and only wrapping it in a trajectory in the generate method.

  3. sroet commented on Jan 18, 2022

    @sroet
    MemberAuthor

    True, but is there any reason to believe that this is a performance bottleneck in real-world use? I think that we have enough overhead in other places that we'd get better performance improvements elsewhere.

    I would guess so as well (outside of strange toy-engines that are both fast and generate long trajectories). This was just a thing I noticed when looking over that PR and I made this issue to get it off my (mental) list. I agree that this should not have any priority.

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions