holoviz / panel

Panel: The powerful data exploration & web app framework for Python
https://panel.holoviz.org
BSD 3-Clause "New" or "Revised" License
4.58k stars 499 forks source link

Speed up the Markdown pane #4287

Open MarcSkovMadsen opened 1 year ago

MarcSkovMadsen commented 1 year ago

I'm working on #4281

I can see that for a static Markdown document ~15% of the launch time is spent on converting the Markdown. As the Markdown is static it should be possible to just convert this once and for all.

I see users of data apps being very happy about using Markdown to add documentation, navigation, images and videos to their apps. But the Markdown is normally static. Thus not caching the converted Markdown is a big overhead.

Reproduce

# home.py
import panel as pn

pn.extension(sizing_mode="stretch_width")

SECTION = """
Panel works really well with the visualization tools you already know and love like [Altair/ Vega](https://panel.holoviz.org/reference/panes/Vega.html), [Bokeh](https://panel.holoviz.org/reference/panes/Bokeh.html), [Datashader](https://datashader.org/), [Deck.gl/ pydeck](https://panel.holoviz.org/reference/panes/DeckGL.html), [Echarts/ pyecharts](https://panel.holoviz.org/reference/panes/ECharts.html), [Folium](https://panel.holoviz.org/reference/panes/Folium.html), [HoloViews](https://holoviews.org/), [hvPlot](https://hvplot.holoviz.org), [plotnine](https://panel.holoviz.org/reference/panes/Matplotlib.html), [Matplotlib](https://panel.holoviz.org/reference/panes/Matplotlib.html), [Plotly](https://panel.holoviz.org/reference/panes/Plotly.html), [PyVista/ VTK](https://panel.holoviz.org/reference/panes/VTK.html), [Seaborn](https://panel.holoviz.org/gallery/styles/SeabornStyle.html) and more. Panel also works with the [ipywidgets](https://panel.holoviz.org/reference/panes/IPyWidget.html) ecosystem.

<img src="https://user-images.githubusercontent.com/42288570/211983400-3315ad0a-866a-4916-8809-6fc38eca34d9.gif" height=400 alt="Pythons DataViz works with Panel"></img>
"""

NAVIGATION = """
## Navigation

[home](home)
[dashboard](dashboard)
"""

pn.template.FastListTemplate(
    site="Panel", site_url="https://panel.holoviz.org",
    title="Home", main=[SECTION], sidebar=[NAVIGATION],
    main_max_width="900px",
).servable()
panel serve home.py --admin --profiler pyinstrument

open /home 10 times open /admin

image

MarcSkovMadsen commented 1 year ago

I would recommend using functools.cache or something similar and then cache the 64 latest conversions or similar.

philippjfr commented 1 year ago

Reasonable suggestion but I think we're going to move to client-side markdown rendering anyway.

MarcSkovMadsen commented 1 year ago

It seems we will not be moving to client side rendering. We just switched to market-it-py on server side.

philippjfr commented 1 year ago

Not right away anyway, in the long run we may very well do so.

philippjfr commented 1 year ago

Just pushed a small change into https://github.com/holoviz/panel/pull/4693 that will cache the markdown renderer. Seeing a 2-3x rendering performance improvement over the old markdown renderer.