Any macOS / Conda users?

77 views
Skip to first unread message

Michael Orlitzky

unread,
Nov 20, 2025, 6:00:24 PM (3 days ago) Nov 20
to sage-...@googlegroups.com
I've been making infrequent progress eliminating the "slow doctest"
warnings that appear on every pull request. In most cases, I can
easily reproduce the problem because my CPU is slower than the CI.

But, there are many tests that are slow only on macOS/Conda, and they
are seemingly slow for no reason. You can take any open pull request
as an example:

https://github.com/sagemath/sage/pull/41200/files

If you scroll down to the "slow doctest" annotations, you'll
eventually see tests that ran slow on macOS/Conda but nowhere else.

I opened an issue for this a while ago:

https://github.com/sagemath/sage/issues/40825

I am wondering if maybe the macOS binaries available on Conda are
unoptimized, or something like that. Since this is a niche issue and
most of us don't have access to macOS... if you know anyone using
Conda on macOS, please ask them if everything is slow.

Tobia...@gmx.de

unread,
Nov 21, 2025, 3:16:36 PM (2 days ago) Nov 21
to sage-devel
I compared the execution times of the ubuntu vs macos runs (for the linked PR, Python 3.12).

In general, the tests take more or less the same time on macos as on ubuntu.


compare1.png

But there are a couple of test files though that are considerably slower on macos:

compare2.png

compare3.png

Most of them seem to be related to curves / polyhedron. So perhaps its only a certain db that is way slower to init/query on macos?

Michael Orlitzky

unread,
Nov 22, 2025, 9:11:05 AM (yesterday) Nov 22
to 'Tobia...@gmx.de' via sage-devel
On 2025-11-21 12:16:36, 'Tobia...@gmx.de' via sage-devel wrote:
> I compared the execution times of the ubuntu vs macos runs (for the linked
> PR, Python 3.12).
>
> In general, the tests take more or less the same time on macos as on ubuntu.

Thanks, that's helpful.


> Most of them seem to be related to curves / polyhedron. So perhaps its only
> a certain db that is way slower to init/query on macos?

There are others that don't fit this explanation though. For example,

sage: x,y,z = SR.var('x,y,z')
sage: [d] = solve_mod([5*x + y == 3, 2*x - 3*y == 9],
3*5*7*11*19*23*29,
solution_dict = True)

is consistently slow (~13 cpu seconds) on macOS, but takes ~1.3s on my
slow CPU with an empty cache.

In finite fields, there's

sage: p = 141 * 2^141 + 1
sage: S.<x> = GF(p)[]
sage: f = S.irreducible_element(2)
sage: k.<y> = S.quotient_ring(f)
sage: k in Fields()
True
sage: k(2).sqrt(algorithm="cipolla")^2 == k(2)
True

that is consistently slower (~9s) on macOS than on my very slow CPU
(~3s). A %prun of one of these tests on a machine where it's slow
would hopefully identity the problem.

Dima Pasechnik

unread,
Nov 22, 2025, 1:59:51 PM (22 hours ago) Nov 22
to sage-...@googlegroups.com
On Sat, Nov 22, 2025 at 8:11 AM Michael Orlitzky <mic...@orlitzky.com> wrote:
>
> On 2025-11-21 12:16:36, 'Tobia...@gmx.de' via sage-devel wrote:
> > I compared the execution times of the ubuntu vs macos runs (for the linked
> > PR, Python 3.12).
> >
> > In general, the tests take more or less the same time on macos as on ubuntu.
>
> Thanks, that's helpful.
>
>
> > Most of them seem to be related to curves / polyhedron. So perhaps its only
> > a certain db that is way slower to init/query on macos?
>
> There are others that don't fit this explanation though. For example,
>
> sage: x,y,z = SR.var('x,y,z')
> sage: [d] = solve_mod([5*x + y == 3, 2*x - 3*y == 9],
> 3*5*7*11*19*23*29,
> solution_dict = True)

On an Intel Mac, latest beta (10.8.beta9) Homebrew Python 3.13:
(Darwin xxxxxx.local 24.6.0 Darwin Kernel Version 24.6.0: Wed Oct 15
21:12:21 PDT 2025; root:xnu-11417.140.69.703.14~1/RELEASE_X86_64
x86_64)

%prun solve_mod([5*x + y == 3, 2*x - 3*y == 9], 3*5*7*11*19*23*29,
solution_dict = True)

9495 function calls (9365 primitive calls) in 13.489 seconds

Ordered by: internal time

ncalls tottime percall cumtime percall filename:lineno(function)
2039 13.336 0.007 13.339 0.007 relation.py:1818(<genexpr>)
35 0.076 0.002 0.076 0.002 {built-in method
_functools.reduce}
14 0.042 0.003 0.121 0.009
expression_conversions.py:978(relation)
7 0.008 0.001 0.008 0.001
polynomial_ring_constructor.py:837(_multi_variate)
2 0.007 0.004 0.007 0.004 {method '__exit__' of
'sqlite3.Connection' objects}
7 0.004 0.001 13.457 1.922
relation.py:1734(_solve_mod_prime_power)
1 0.004 0.004 0.004 0.004 {method 'execute' of
'sqlite3.Connection' objects}

Thus, dog-slow symbolic ring "relation" code.

(profiles on a modern Intel CPU, Linux, look similar, but are just
50-100 times faster)

On M1 Mac Studio (machine hosted by William), latest beta (10.8.beta9)
Homebrew Python 3.13, it's almost as bad as on Intel
(Darwin studio.local 24.6.0 Darwin Kernel Version 24.6.0: Mon Jul 14
11:30:29 PDT 2025; root:xnu-11417.140.69~1/RELEASE_ARM64_T6000 arm64)

9632 function calls (9513 primitive calls) in 9.672 seconds

Ordered by: internal time

ncalls tottime percall cumtime percall filename:lineno(function)
2039 9.565 0.005 9.566 0.005 relation.py:1818(<genexpr>)
35 0.054 0.002 0.054 0.002 {built-in method
_functools.reduce}
14 0.031 0.002 0.079 0.006
expression_conversions.py:978(relation)
112/14 0.007 0.000 0.086 0.006
expression_conversions.py:152(__call__)
2 0.005 0.003 0.005 0.003 {method '__exit__' of
'sqlite3.Connection' objects}
1 0.003 0.003 0.003 0.003 {method 'execute' of
'sqlite3.Connection' objects}
7 0.001 0.000 9.633 1.376
relation.py:1734(_solve_mod_prime_power)



> is consistently slow (~13 cpu seconds) on macOS, but takes ~1.3s on my
> slow CPU with an empty cache.
>
> In finite fields, there's
>
> sage: p = 141 * 2^141 + 1
> sage: S.<x> = GF(p)[]
> sage: f = S.irreducible_element(2)
> sage: k.<y> = S.quotient_ring(f)
> sage: k in Fields()
> True
> sage: k(2).sqrt(algorithm="cipolla")^2 == k(2)
> True
>
> that is consistently slower (~9s) on macOS than on my very slow CPU
> (~3s). A %prun of one of these tests on a machine where it's slow
> would hopefully identity the problem.
from the last example:

%prun k(2).sqrt(algorithm="cipolla")^2 == k(2)

122239 function calls (122238 primitive calls) in 9.261 seconds

Ordered by: internal time

ncalls tottime percall cumtime percall filename:lineno(function)
307 4.847 0.016 9.157 0.030
polynomial_quotient_ring_element.py:385(__invert__)
614 4.260 0.007 4.264 0.007
multi_polynomial_sequence.py:213(PolynomialSequence)
7960 0.029 0.000 0.042 0.000
polynomial_ring.py:335(_element_constructor_)
4303 0.020 0.000 0.039 0.000
polynomial_quotient_ring_element.py:108(__init__)

Thus, dog-slow arithmetic in polynomial quotient rings.

Not much better on M1 Mac.
(roughly the same picture as in the previous example, i.e. a bit
faster, but not much)

HTH
Dima

Michael Orlitzky

unread,
Nov 22, 2025, 4:21:14 PM (20 hours ago) Nov 22
to sage-...@googlegroups.com
On 2025-11-22 11:57:32, Dima Pasechnik wrote:
> ncalls tottime percall cumtime percall filename:lineno(function)
> 2039 13.336 0.007 13.339 0.007 relation.py:1818(<genexpr>)
> ...
>
> Thus, dog-slow symbolic ring "relation" code.
>
>
> ncalls tottime percall cumtime percall filename:lineno(function)
> 307 4.847 0.016 9.157 0.030 polynomial_quotient_ring_element.py:385(__invert__)
>
> Thus, dog-slow arithmetic in polynomial quotient rings.

Thanks! These could actually be the same problem. The slow code in
relation.py is coercing a bunch of symbolic equations into a
polynomial ring.

Maybe it's Singular being slow or something like that.
Reply all
Reply to author
Forward
0 new messages