Skip to content

Considerably Speedup CLITest by caching EmbbededScripting absolute paths - #5714

Open
jmarrec wants to merge 1 commit into
developfrom
CLITtest_speedup
Open

jmarrec wants to merge 1 commit into
developfrom
CLITtest_speedup

Conversation

@jmarrec

@jmarrec jmarrec commented Nov 27, 2026

Copy link
Copy Markdown
Collaborator

Pull request overview

Embedded Dir.glob: compute the absolute embedded file names once instead of on every glob (~20s per require 'minitest/autorun')

The CLI tests take about 80% of CTest time on Windows (69% on macOS x64). Each one wastes about 20s before it starts: require 'minitest/autorun' loads minitest's plugins through Gem.find_files("minitest/*_plugin.rb"), which globs once per gem path (about 150 globs). For embedded paths, our Dir.glob override in ruby/engine/embedded_help.rb called OpenStudio.get_absolute_path on every embedded file (6379) for every glob: about a million calls, for a result that never changes.

This computes the absolute names once, the first time they're needed, in EmbeddedScripting.absoluteFileNames. The matching logic is unchanged. The cache is frozen, and each match is returned as a copy, so callers still get a string they can modify, as before.

It isn't only about the tests: anything in the CLI that globs embedded files is faster too (requiring gems, Gem.find_files, measures, etc).

Timings (CI run https://github.com/jmarrec/OpenStudio/actions/runs/45789840585 for the "before" numbers):

  • Windows: 162 CLI tests took 5500s of 6833s total test time (80%), about 33s each, even trivial ones. macOS x64: 5742s of 8284s (69%).
  • Locally, CLITest-Date_Test-*: 21.7s -> 2.8s per test (the test itself takes 0.06s).
  • require 'minitest/autorun' plus openstudio-standards and openstudio/extension: 24.8s -> 4.4s.

Testing:

  • Logged every Dir.glob call (arguments and results) with the old and new CLI while running the requires above, a Gem.find_files, and extra patterns covering base:, braces, ?, an array pattern, FNM_DOTMATCH, FNM_CASEFOLD and Dir[]. Both logs are identical: 172 calls, 10436 matches, same order.
  • get_absolute_path gives the same answer every time for embedded names: they all start with :/, so File.expand_path gets an absolute path and doesn't depend on the current directory (on Windows the drive letter is stripped).

Timings

Local

On my Ubuntu 24.04, Ryzen 1800X (8 cores, 16 threads), 32GB RAM.

It's 8x faster

Running ctest -R "CLITest|OpenStudioCLI" -j 12, 224/224 passed both before and after:

Before After
Wall time 8m48s 2m43s
CLITest (162 tests) 5210s, median 31.8s 655s, median 3.6s
OpenStudioCLI (62 tests) 551s, median 1.6s 396s, median 1.3s
Total test time 5761s 1050s

A few examples:

  • CLITest-Date_Test-to_s: 31.5s -> 2.9s
  • CLITest-test_bundle-bundle_native_embedded: 55.5s -> 23.1s
  • OpenStudioCLI.test_bcl_measure_templates: 129.8s -> 47.7

On CI

Develop run: https://github.com/jmarrec/OpenStudio/actions/runs/45855664074

ctest_timings() {
  local run_id="${1:?usage: ctest_timings <run_id> [repo]}"
  local repo="${2:-jmarrec/OpenStudio}"
  gh api "repos/$repo/actions/runs/$run_id/jobs" --paginate --jq '
    .jobs[] | .name as $j | .steps[] | select(.name == "Run CTest suite")
    | if .started_at == null then "\($j): \(.status)"
      elif .completed_at == null then "\($j): \(.status) (running for \((now - (.started_at | fromdate)) / 60 | floor)m)"
      else ((.completed_at | fromdate) - (.started_at | fromdate)) as $d
        | "\($j): \(.conclusion) \($d / 60 | floor)m\($d % 60)s"
      end'
}

These are CTest step times, develop run 45855664074 against this PR #15 run 5859885716. Both runs are on the same 0390427 base, so the only difference is the CLITest fix.

Platform develop PR #15 Delta Speedup
Ubuntu 24.04 x64 21m11 4m44 −16m27 4.5×
Ubuntu 24.04 ARM64 13m06 4m10 −8m56 3.1×
CentOS 9 x64 15m41 4m33 −11m08 3.4×
Windows 2022 x64 28m21 8m28 −19m53 3.3×
macOS x64 37m47 19m04 −18m43 2.0×
macOS ARM64 13m38 7m08 −6m30 1.9×
Total 129m44 48m07 −81m37 2.7×

All tests passed in both runs.
The develop numbers come from cold-cache builds, but CTest time doesn't depend on ccache, so the comparison holds. The develop macOS ARM64 figure comes from the re-run job 140117068500

Pull Request Author

  • Model API Changes / Additions
  • Any new or modified fields have been implemented in the EnergyPlus ForwardTranslator (and ReverseTranslator as appropriate)
  • Model API methods are tested (in src/model/test)
  • EnergyPlus ForwardTranslator Tests (in src/energyplus/Test)
  • If a new object or method, added a test in NREL/OpenStudio-resources: Add Link
  • If needed, added VersionTranslation rules for the objects (src/osversion/VersionTranslator.cpp)
  • Verified that C# bindings built fine on Windows, partial classes used as needed, etc.
  • All new and existing tests passes
  • If methods have been deprecated, update rest of code to use the new methods

Labels:

  • If change to an IDD file, add the label IDDChange
  • If breaking existing API, add the label APIChange
  • If deemed ready, add label Pull Request - Ready for CI so that CI builds your PR

Review Checklist

This will not be exhaustively relevant to every PR.

  • Perform a Code Review on GitHub
  • Code Style, strip trailing whitespace, etc.
  • All related changes have been implemented: model changes, model tests, FT changes, FT tests, VersionTranslation, OS App
  • Labeling is ok
  • If defect, verify by running develop branch and reproducing defect, then running PR and reproducing fix
  • If feature, test running new feature, try creative ways to break it
  • CI status: all green or justified

…ead of on every glob (~20s per require 'minitest/autorun')

The CLI tests take about 80% of CTest time on Windows (69% on macOS x64). Each one wastes about 20s before it starts: `require 'minitest/autorun'` loads minitest's plugins through `Gem.find_files("minitest/*_plugin.rb")`, which globs once per gem path (about 150 globs). For embedded paths, our `Dir.glob` override in `ruby/engine/embedded_help.rb` called `OpenStudio.get_absolute_path` on every embedded file (6379) for every glob: about a million calls, for a result that never changes.

This computes the absolute names once, the first time they're needed, in `EmbeddedScripting.absoluteFileNames`. The matching logic is unchanged. The cache is frozen, and each match is returned as a copy, so callers still get a string they can modify, as before.

It isn't only about the tests: anything in the CLI that globs embedded files is faster too (requiring gems, `Gem.find_files`, measures, etc).

Timings (CI run https://github.com/jmarrec/OpenStudio/actions/runs/45789840585 for the "before" numbers):
- Windows: 162 CLI tests took 5500s of 6833s total test time (80%), about 33s each, even trivial ones. macOS x64: 5742s of 8284s (69%).
- Locally, `CLITest-Date_Test-*`: 21.7s -> 2.8s per test (the test itself takes 0.06s).
- `require 'minitest/autorun'` plus `openstudio-standards` and `openstudio/extension`: 24.8s -> 4.4s.

Testing:
- Logged every `Dir.glob` call (arguments and results) with the old and new CLI while running the requires above, a `Gem.find_files`, and extra patterns covering `base:`, braces, `?`, an array pattern, `FNM_DOTMATCH`, `FNM_CASEFOLD` and `Dir[]`. Both logs are identical: 172 calls, 10436 matches, same order.
- `get_absolute_path` gives the same answer every time for embedded names: they all start with `:/`, so `File.expand_path` gets an absolute path and doesn't depend on the current directory (on Windows the drive letter is stripped).

### Timings

On my Ubuntu 24.04, Ryzen 1800X (8 cores, 16 threads), 32GB RAM.

It's 8x faster

Running `ctest -R "CLITest|OpenStudioCLI" -j 12`, 224/224 passed both before and after:

|                          | Before          | After           |
|--------------------------|-----------------|-----------------|
| Wall time                | 8m48s           | 2m43s           |
| CLITest (162 tests)      | 5210s, median 31.8s | 655s, median 3.6s |
| OpenStudioCLI (62 tests) | 551s, median 1.6s   | 396s, median 1.3s |
| Total test time          | 5761s           | 1050s           |

A few examples:
- `CLITest-Date_Test-to_s`: 31.5s -> 2.9s
- `CLITest-test_bundle-bundle_native_embedded`: 55.5s -> 23.1s
- `OpenStudioCLI.test_bcl_measure_templates`: 129.8s -> 47.7
@jmarrec

jmarrec commented Nov 27, 2026

Copy link
Copy Markdown
Collaborator Author

Demo of this + #5713

image

@jmarrec

jmarrec commented Nov 27, 2026 •

Copy link
Copy Markdown
Collaborator Author

On this repo: develop: https://github.com/NatLabRockies/OpenStudio/actions/runs/45962627202
This PR 5714: https://github.com/NatLabRockies/OpenStudio/actions/runs/45982069705

PR #5714 (run 45982069705) passed on all 6 platforms, macOS x64 included. Its slowest job took 39 min, against 141 min for develop's slowest job (run 45962627202, which started with no cache).

Platform Build: develop → PR CTest: develop → PR Job: develop → PR
Ubuntu x64 50m39 → 5m04 (10.0×) 14m36 → 4m46 (3.1×) 69m36 → 15m01 (4.6×)
Ubuntu ARM64 61m18 → 5m06 (12.0×) 13m31 → 4m10 (3.2×) 79m30 → 14m30 (5.5×)
CentOS 9 92m03 → 5m05 (18.1×) 24m51 → 4m43 (5.3×) 127m38 → 19m44 (6.5×)
Windows 87m22 → 15m38 (5.6×) 33m19 → 11m22 (2.9×) 141m10 → 39m12 (3.6×)
macOS x64 71m49 → 17m25 (4.1×) 33m00 → 11m16 (2.9×) 122m08 → 38m58 (3.1×)
macOS ARM64 54m47 → 13m57 (3.9×) 18m39 → 7m46 (2.4×) 84m05 → 31m51 (2.6×)
Total 417m58 → 62m15 (6.7×) 137m56 → 44m03 (3.1×) 624m07 → 159m16 (3.9×)
  • Build: the speedup comes from the PR restoring develop's ccache.
  • CTest: the speedup comes from the PR's CLITest fix, and is roughly the same as on the fork.
  • macOS x64: its CTest took 11m16 here against 19m04 on the fork, so that runner's speed varies a lot from one run to the next.

@jmarrec
jmarrec requested review from anchapin and kbenne November 27, 2026 16:28

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant