Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate Diagrams in Parallel #432

Open
KartikSoneji opened this issue Sep 3, 2023 · 4 comments
Open

Generate Diagrams in Parallel #432

KartikSoneji opened this issue Sep 3, 2023 · 4 comments

Comments

@KartikSoneji
Copy link

At the moment, it looks like the extension generates diagrams as it comes across them, which can get quite slow.
Is it possible to generate diagrams in parallel with a pool of n workers?
That would greatly speed up generation for documents with many diagrams and a slow processor like mermaid.

Not sure if it would need changes to the asciidoctor extension system, but either way I'll be more than happy to help.

@pepijnve
Copy link
Member

pepijnve commented Sep 3, 2023

The extension system isn't designed for asynchronous operation as far as I know. The callback hooks are all synchronous. It might be possible to hack together a solution that achieves some degree of asynchrony, but I think this would be at the cost of reliability.

@mojavelinux wdyt?

@mojavelinux
Copy link
Member

In theory, it would be possible to replace the diagram with a marker, then start working on those markers in the background. The caller would have to force a join when the document is done converting. But this is unlikely to help except for the specific circumstances when the document is extremely large.

I think a better approach would be to separate diagram generation from processing altogether if you want to be able to work in this mode. That would not be the behavior/responsibility of this extension (as I would view it to be out of scope), but rather a different one that makes use of this extension for that purpose/workflow. In other words, you would need to think about separating diagram generation from AsciiDoc conversion entirely.

@KartikSoneji
Copy link
Author

Except for inline images, the actual generation is independent of the markup, right?
Can't the extension return the markup in those cases at least?

@pepijnve
Copy link
Member

pepijnve commented Sep 8, 2023

Perhaps we could make a companion post processor extension to handle this. When it's loaded, the diagram extension goes through the usual motions, but instead of actually producing the images it collects all the "production instructions". Then in the post processor you execute those instructions in parallel. The post processor could still be synchronous by waiting for the work queue to be completed entirely.

PRs welcome ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants