mikitex70 / plantuml-markdown

PlantUML plugin for Python-Markdown
BSD 2-Clause "Simplified" License
196 stars 55 forks source link

Cashing output or making an option to disable plugin #27

Closed majkinetor closed 5 years ago

majkinetor commented 5 years ago

I use this plugin within mkdocs system.

I converted my custom plantuml build script to use this plugin. My script simply found all *.puml.md files, rendered them to svg files and I used linke to images.

Now I moved all those puml files into the documentation and rendering pages take a very long time. I have around 15 plantuml diagrams total (not much) and building static site takes around 30-s each time and this is particularly problematic with real time serving (each CTRL+S takes 30s to show in browser). With my previous setup this didn't happen as I regenerated SVGs only if original puml files changed.

So,

Is it possible to cache the output so that if there are no changes to the input, plugin will reuse last output.

If not, please provide option enable: true/false that can take input from environment variable. This is, for example, how mkdocs pdf export plugin solves the problem of slownes of pdf printing everything on each change - on dev machine this is disabled but on production deployment this is enabled. This way when you write other parts of documentation (not plantuml, which is 99% of the time) the speed of build and serve will be as fast as possible. When you want to view UML you can either use external app or enable the plugin in config again. Furthermore, this can be even better if there is direct option to override it like this:

```yaml
    - plantuml_markdown:        
        enable: false
```

```plantuml
A->B : THIS WILL NOT RENDER
```

```plantuml enable="true"
A->B: THIS WILL OVERRIDE CURRENT CONFIG VALUE
```

In this case we have best option - the stuff you currently work on can be seen ASAP in browser, the stuff you know is good is skipped, and everything is turned on/off any time.

majkinetor commented 5 years ago

This issue contains the same problem #19 (reported by @nalaka) but solved via online render.

This solution can not be used always (there is no internet access), can not be relied upon (even if there is, network may be down) is problematic behind the proxy and most of all, still way slower then above approach.

mikitex70 commented 5 years ago

I've added support for caching. You can try the version in the develop branch and set the config option cachedir to a path where to store cached diagrams. Soon I will release a package installable with pip, but I would like to know if that implementation can be usable.

mikitex70 commented 5 years ago

Released version 3.1.0 with the diagram caching. Thanks for your suggestion.

majkinetor commented 5 years ago

Tested it, works nice! Thanks a lot.

nalaka commented 5 years ago

This is a great improvement. The server and cachedir options finally lets me work with a Mkdocs project- heavy with PlantUML diagrams, without disabling live reloading.

Thanks @mikitex70 for the enhancement and @majkinetor for the suggestion!

mschoettle commented 5 months ago

@mikitex70 I stumbled across this because live-reloading was quite slow with around 10 diagrams. Once I enabled caching the build time went from 10s to around 4-5s. After investigating I noticed that it is due to the .map file being re-rendered.

This happens when the map file is empty. diagram is b'' and the if diagram: evaluates to False.

https://github.com/mikitex70/plantuml-markdown/blob/3c4f8432bc2c79edf1bc5cf5e61162676052ec13/plantuml_markdown/plantuml_markdown.py#L349

I disabled image_maps which fixed the problem. I wonder if this is a bug and the condition should be if diagram is not None instead?

mikitex70 commented 5 months ago

Yes, you are right, this small tweak improves performance when generating PNG images from diagrams without hyperlinks. I've just released version 3.9.5. Thanks for the report.

mschoettle commented 5 months ago

Thanks a lot for the fix! Just tested it 👍