Skip to content

Ops unit tests are too slow #102

Closed as not planned
Closed as not planned

Description

@hinerm

Here's the current summary of unit test times on my Windows desktop:
image

The fact that the whole reactor takes 6 minutes is prohibitive for development.

I am in favor of having a single Ops environment that gets reused across tests, at least for default builds. For CI we could have full encapsulation and rebuild the environment each time.

Activity

  1. added this to the 1.0.0 milestone on Oct 31, 2022
  2. ctrueden commented on Oct 31, 2022

    @ctrueden
    Member

    I agree and have been meaning to file an issue about this, thanks. We should reuse the same environment, yeah. Also on CI, because I think slow CI is also a hindrance.

  3. ctrueden commented on Nov 8, 2022

    @ctrueden
    Member

    @hinerm's PR scijava/incubator#65 improves matters. Still room for further optimization, but imagej-ops2 has a lot of tests, some of which are computationally intensive, so there will be limits to how lightning-quick we can make it. @hinerm Are you OK closing this issue now, or do you want to leave it open till we have time to do another optimization pass?

  4. hinerm commented on Nov 8, 2022

    @hinerm
    MemberAuthor

    @ctrueden let's do a run of profiling the tests and then if that doesn't turn up anything obvious we can close this issue!

  5. ctrueden commented on Nov 8, 2022

    @ctrueden
    Member

    I did some profiling with the JDK Flight Recorder + VisualVM. Nothing definitive to report so far, but here is an explanation of what I did, and things I saw that probably merit further investigation:

    I wanted to profile the scijava incubator code using IntelliJ. Unfortunately, the Community edition of IDEA does not have profiling tools integrated into the IDE. So I turned to the JDK Flight Recorder (JFR), which is open source as of OpenJDK 11. You can enable it by creating a run configuration with an additional flag: -XX:StartFlightRecording:filename="/home/curtis/Desktop/imagej-ops2.jfr" which points to where you want your JFR capture to be saved. Then launch that run configuration to generate it.

    The next part, which I found a little tricky, is getting a VisualVM installed that supports JFR files. The VisualVM I installed on Ubuntu via apt install visualvm, v2.0.6, does not support JFR files out of the box; when you try to load one, it tells you to install a plugin called VisualVM-JFR-Generic, but it's not actually available on the list when you try. So an easier path forward for me was to download GraalVM 22.3.0, and then install its VisualVM support, which is done simply via bin/gu install visualvm, at which point it appears as jvisualvm in the GraalVM installation's bin folder.

    Then you can launch VisualVM and open up the JFR file using File → Load... A tab will open with an overview.

    • There is another set of tabs on the bottom of the GUI with other views; the Sampler tab here is interesting. Click it.
    • Then click the CPU button.
    • Then click the "Hot spots" view (tiny table-icon button next to arrow button in the View toolbar).
    • The computeBin methods of the various thresholding methods appear a lot; maybe we can improve how those get used, and/or optimize any of those implementations.
    • In the "Forward calls" view (the arrow button, enabled initially after clicking CPU), filtering by scijava (by right-clicking any thread and choosing "Filter" from the popup menu), we can also see that therapi methods are in the news a lot. So our plan to discover as efficiently as possible by loading op specifications from YAML files instead is likely going to improve runtime performance here as well.

    This Medium article is also potentially interesting, but I haven't gone through it in depth yet.

  6. hinerm commented on Nov 9, 2022

    @hinerm
    MemberAuthor

    So I'm still getting familiar with analyzing JFR output but have been looking at a capture of the LilCQTest

    I looked at the Hot Spots in the Sampler tab > CPU and it says 1.2s were spent creating java.lang.Error. If you right-click on an entry in Hot Spots and go to "Find in Forward Calls" it will highlight one execution path to that item. You can continue to click and "Find in Forward Calls" to cycle through use-cases. (You can also do this with Reverse Calls but I find Forward a little easier to mentally parse).

    Some items I've found:

    338ms in net.imagej.ops.ops2.Creators.<init>
    image

    468ms creating synthesized parameters
    image

    240ms getting therapi javadoc
    image

    A total of ~1.5s checking File.exists() in SCIFIO when opening the different images for this test
    image

    A significant amount of time doing disk IO with therapi:
    image

    I also noticed we are creating a SJ1 context?
    image

  7. ctrueden commented on Nov 10, 2022

    @ctrueden
    Member

    Thanks @hinerm for digging!

    I also noticed we are creating a SJ1 context?

    SJC2, but yeah. SCIFIO is built on SciJava Common, so we're not getting away from this at test time unless: A) we stop using SCIFIO; or B) we port SCIFIO to the incubator and change its plugin model to use JPMS instead.

  8. gselzer commented on Sep 7, 2023

    @gselzer
    Member

    @hinerm @ctrueden this issue provides no concrete milestones (i.e. how fast is fast enough to consider this issue closed), I'm going to close this issue and make smaller issues for the particular issues @hinerm (and now I) am finding:

    338ms in net.imagej.ops.ops2.Creators.

    I could not replicate this so I'm ignoring it.

    468ms creating synthesized parameters

    I could replicate this - see #131

    240ms getting therapi javadoc

    I could replicate this, but I'm going to ignore it for now because scijava/incubator#79 will remove the therapi javadoc parsing.

    A total of ~1.5s checking File.exists() in SCIFIO when opening the different images for this test

    I could not replicate this so I'm ignoring it.

    A significant amount of time doing disk IO with therapi:

    See above with the therapi stuff.

    It's probably worth running the profiler again once we get the YAML work merged, to see if that pathway exhibits the same performance issues...

  9. added a commit that references this issue on May 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions