Commit
3 years ago
gh-35039: add lazy_string in matrix2.pyx <!-- ^^^^^ Please provide a concise, informative and self-explanatory title. Don't put issue numbers in there, do this in the PR body below. For example, instead of "Fixes #1234" use "Introduce new method to calculate 1+1" --> ### 📚 Description Formatting verbose messages in the method right_kernel could be quite slow (even when the message is never printed). We use the functionality lazy_string in order to avoid the formatting. Also, just calling `verbose()` is slow when just a cache lookup is needed. #### Timings Before: ``` sage: K.<a> = NumberField(x^2 - 2, embedding=1) sage: A = MatrixSpace(K, 1, 1).one() sage: %time _ = A.right_kernel() CPU times: user 23 ms, sys: 3 ms, total: 26 ms Wall time: 26.1 ms sage: %timeit A.right_kernel() # cache lookup 2.16 µs ± 70.3 ns per loop (mean ± std. dev. of 7 runs, 100,000 loops each) ``` After: ``` sage: K.<a> = NumberField(x^2 - 2, embedding=1) sage: A = MatrixSpace(K, 1, 1).one() sage: %time _ = A.right_kernel() CPU times: user 11 ms, sys: 10 µs, total: 11 ms Wall time: 11.2 ms sage: %timeit A.right_kernel() # cache lookup 103 ns ± 1.55 ns per loop (mean ± std. dev. of 7 runs, 10,000,000 loops each) ``` ### 📝 Checklist - [X] I have made sure that the title is self-explanatory and the description concisely explains the PR. - [x] I have linked an issue or discussion. **No**, this was discussed at SageDays 117, we have no linked issue on GitHub for this. - [x] I have created tests covering the changes. **No**, there are already tests testing that verbose still works correctly. - [x] I have updated the documentation accordingly. **No**, there are no user-facing changes. URL: https://github.com/sagemath/sage/pull/35039 Reported by: Xavier Caruso Reviewer(s): Frédéric Chapoton, Sébastien Labbé, Vincent Delecroix
Author
Release Manager
Loading