matplotlib / matplotlib/matplotlib

[MNT]: mathtext.MathTextParser is slow

Open
#20,821 15 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

keep Performance topic: text/mathtext
Dominant language
Python
Stars
23.2k
Forks
8.5k
Avg merge
1d 6h
Merged PRs (30d)
66

Description

### Summary

The mathtext.MathTextParser is a performance bottleneck.

I profiled my interactive app that uses PyQt and matplotlib to draw complex plots with very little text and yet significant time (20 %) is spend in the mathtext.MathTextParser. See
[profile_graph.pdf](https://github.com/matplotlib/matplotlib/files/6963037/profile_graph.pdf)

### Proposed fix

The parser is using pyparsing internally and could potentially be speed up by switching to [lark](https://github.com/lark-parser/lark).

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with matplotlib's mathtext.MathTextParser and reproduce the reported profiling scenario using complex plots with little text. Compare the parser's current pyparsing behavior with the proposed lark approach, then measure whether parsing time improves without changing rendered output. The profile_graph.pdf provides the reported performance baseline.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
data-visualization, performance
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
32/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.