Conversation
|
Thanks @kp992. Now that #938 is merged, could you rebase this onto Two more things. #930 asks for a before/after warm-cache |
7ae4be8 to
8a7da64
Compare
Four guvectorize callables compiled at import time are now compiled lazily on first call: _probvec_parallel, _probvec_cpu, _sample_without_replacement (_ints_arr_to_bits). Gufuncs are replaced by thin Python wrapper functions that create the underlying ufunc on first invocation and cache it in a module-level sentinel. _probvec_cpu keeps the same name so the game_theory/random.py import is unchanged. Fixes QuantEcon#930, part of QuantEcon#925.
8a7da64 to
97325b6
Compare
|
Thanks @kp992 — closing this in favour of #957, which opens @oyamad's implementation of the same idea from his Two things decided it. His version builds the gufuncs through memoised factory functions rather than module-level sentinels mutated through One correction that applied to both versions: this PR says "Closes #930", but #930's acceptance criterion 1 — warm-cache Thanks for the work on this. The analysis in your description was accurate and it is what got the approach agreed. |
|
Thanks @mmcky for the review and feedback. Sounds good to me. |
Closes #930, part of #925.
What
Four guvectorize callables compiled at
import quantecontime are now compiled lazily on first call:_probvec_parallelrandom/utilities.py_probvec_cpurandom/utilities.py_sample_without_replacementrandom/utilities.py@guvectorizedecorator → lazy wrapper_ints_arr_to_bitsgame_theory/vertex_enumeration.pyHow
Gufuncs are replaced by thin Python wrapper functions that create the underlying ufunc on first call and cache it in a module-level sentinel.
_probvec_cpukeeps the same name so thegame_theory/random.pyimport is unchanged.Why this matters for WASM
On native CPython, eager compilation costs milliseconds. In a JupyterLite/WASM kernel, each compile is a full LLVM optimise + WASM object emit + in-process LLD link. The emscripten-forge Numba patches also force-disable
cache=Truefor@guvectorize, so the four gufunc compiles were paid on every session on the critical import path of every notebook.Public API
No change.
qe.random.probvec(..., parallel=...),qe.random.sample_without_replacement(...), andqe.game_theory.vertex_enumeration(...)are unaffected.