Skip to content

Conversation

@joshuarwood
Copy link
Contributor

This PR provides a 25x speed improvement on my M3 MacBook Pro for the interpolate() method of the unbinned NaivePoisson background fit.

Details

The unbinned NaivePoisson background fit contains an interpolate() method for retrieving background values. This method regenerates the same 1D spline from the underlying _times and _rates arrays each time it's called. This takes about 5 ms on my M3 MacBook Pro for 1000 sec of GBM data. Spline creation time should scale with the event number so it will be longer for higher rates and long time periods.

This PR moves spline generation into the fit() method so that it is only called once during the fit process. Subsequent calls to interpolate() are therefore much faster since we don't need to regenerate the spline. This takes about 0.2 ms on my M3 MacBook Pro for 1000 sec of GBM data.

The change shouldn't impact anything other than speed since the spline interpolation doesn't depend on the tstart, tstop arguments of interpolate(). Unit tests passed successfully.

Here is a plot showing the distributions of call times on my M3 MacBook Pro for main vs this PR:
Screenshot 2025-11-21 at 1 11 43 PM

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.

1 participant