8000 ITC perf improvement, reuse the current bin results by cquiroz · Pull Request #2443 · gemini-hlsw/ocs · GitHub
[go: up one dir, main page]

Skip to content

ITC perf improvement, reuse the current bin results - #2443

Merged
cquiroz merged 2 commits into
mainfrom
perf-pr/06-interpolation-cursor
Nov 2, 2026
Merged

cquiroz merged 2 commits into
mainfrom
perf-pr/06-interpolation-cursor

Conversation

@cquiroz
@cquiroz cquiroz commented Nov 2, 2026
Copy link
Copy Markdown
Contributor

Applying a transmission element to a spectrum called getY(double) once per point. Each call made an interface call, ran two range checks, looked up the bin and computed a new slope. This is correct but it has a cost identified while profiling

This PR adds DefaultArraySpectrum.Interpolator, which keeps the current bin and slope between calls. When the wavelengths come in increasing order, consecutive points that fall in the same bin skip the lookup.

  • TransmissionElement.visit and Instrument.addBackground use the interpolator when the spectrum is a DefaultArraySpectrum. Other spectrum types keep the old getY path.
  • at(x) uses the same expression as getY, with the same operands, so results are bit-identical. Values outside the range still return 0.

Results measured on some test calculations

Time
Before 130 ms
After 104 ms

Convolving a spectrum with a transmission element evaluated getY(double) on
the element for every point: an interface call, two range checks, a bin
lookup and a fresh slope each time, 39 percent of the remaining time in the
profile. DefaultArraySpectrum.Interpolator keeps the current bin and slope
between calls and evaluates the same expression with the same operands, so
results are bit-identical while consecutive points in one bin skip the
lookup. TransmissionElement.visit and Instrument.addBackground use it.

Three alternating harness runs: 130 ms without, 104 ms with, every case
faster, allocation and golden outputs unchanged.
@mergify
mergify Bot commented Nov 2, 2026 •
Copy link
Copy Markdown

This pull request does not currently match the merge queue conditions, so it cannot be queued from here. The box comes back if it matches again.

@cquiroz
cquiroz merged commit 66edd1a into main Nov 2, 2026
4 checks passed
@cquiroz
cquiroz deleted the perf-pr/06-interpolation-cursor branch November 2, 2026 13:49
@cquiroz cquiroz mentioned this pull request Nov 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

0