Repository navigation
Conversation
…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
Collaborator
Author
|
Demo of this + #5713
|
Collaborator
Author
|
On this repo: develop: https://github.com/NatLabRockies/OpenStudio/actions/runs/45962627202 PR #5714 (run
|
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

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 throughGem.find_files("minitest/*_plugin.rb"), which globs once per gem path (about 150 globs). For embedded paths, ourDir.globoverride inruby/engine/embedded_help.rbcalledOpenStudio.get_absolute_pathon 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):
CLITest-Date_Test-*: 21.7s -> 2.8s per test (the test itself takes 0.06s).require 'minitest/autorun'plusopenstudio-standardsandopenstudio/extension: 24.8s -> 4.4s.Testing:
Dir.globcall (arguments and results) with the old and new CLI while running the requires above, aGem.find_files, and extra patterns coveringbase:, braces,?, an array pattern,FNM_DOTMATCH,FNM_CASEFOLDandDir[]. Both logs are identical: 172 calls, 10436 matches, same order.get_absolute_pathgives the same answer every time for embedded names: they all start with:/, soFile.expand_pathgets 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:A few examples:
CLITest-Date_Test-to_s: 31.5s -> 2.9sCLITest-test_bundle-bundle_native_embedded: 55.5s -> 23.1sOpenStudioCLI.test_bcl_measure_templates: 129.8s -> 47.7On CI
Develop run: https://github.com/jmarrec/OpenStudio/actions/runs/45855664074
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.
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
src/model/test)src/energyplus/Test)src/osversion/VersionTranslator.cpp)Labels:
IDDChangeAPIChangePull Request - Ready for CIso that CI builds your PRReview Checklist
This will not be exhaustively relevant to every PR.