I found that pretty print was slow for a long Poly:
```python
from sympy impor…t *
from sympy.polys.domainmatrix import DomainMatrix
a, b, c, d, e, f, g, h, i, j = symbols('a:j')
M = DomainMatrix.from_list_sympy(10, 10, [
[3 - 4*a, -2, 0, 0, 0, 0, 0, 0, 0, 0],
[ -2, 3 - 4*b, -2, 0, 0, 0, 0, 0, 0, 0],
[ 0, -2, 3 - 4*c, -2, 0, 0, 0, 0, 0, 0],
[ 0, 0, -2, 3 - 4*d, -2, 0, 0, 0, 0, 0],
[ 0, 0, 0, -2, 3 - 4*e, -2, 0, 0, 0, 0],
[ 0, 0, 0, 0, -2, 3 - 4*f, -2, 0, 0, 0],
[ 0, 0, 0, 0, 0, -2, 3 - 4*g, -2, 0, 0],
[ 0, 0, 0, 0, 0, 0, -2, 3 - 4*h, -2, 0],
[ 0, 0, 0, 0, 0, 0, 0, -2, 3 - 4*i, -2],
[ 0, 0, 0, 0, 0, 0, 0, 0, -1, 3 - 4*j]])
p = M.charpoly()
import time
start = time.time()
s = pretty(p) # slow
print(time.time() - start)
```
That call to pretty takes 20 seconds on master.
Profiling shows that the bottleneck is actually the `is_combining` function and the call here:
https://github.com/sympy/sympy/blob/4674883018b333ea2049cf88ec04b291c01439a0/sympy/printing/pretty/stringpict.py#L36-L41
I think it's just slow because we have to loop over each individual character of a long string. Probably any way to avoid the Python for loop would help but here's one possibility:
```diff
diff --git a/sympy/printing/pretty/stringpict.py b/sympy/printing/pretty/stringpict.py
index 74bc694b69..e19e7675a2 100644
--- a/sympy/printing/pretty/stringpict.py
+++ b/sympy/printing/pretty/stringpict.py
@@ -33,12 +33,14 @@ def __init__(self, s, baseline=0):
self.baseline = baseline
self.binding = None
+ _remove_combining = dict.fromkeys(list(range(768, 880)) + list(range(8400, 8433)))
+
@staticmethod
def line_width(line):
"""Unicode combining symbols (modifiers) are not ever displayed as
separate symbols and thus shouldn't be counted
"""
- return sum(1 for sym in line if not is_combining(sym))
+ return len(line.translate(stringPict._remove_combining))
@staticmethod
def equalLengths(lines):
```
With that the time to pretty print comes down from 20 seconds to 0.4 seconds.