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

Improvement toc helper performance #4331

Closed
2 tasks done
jiangtj opened this issue May 25, 2020 · 5 comments
Closed
2 tasks done

Improvement toc helper performance #4331

jiangtj opened this issue May 25, 2020 · 5 comments

Comments

@jiangtj
Copy link
Member

jiangtj commented May 25, 2020

Check List

Please check followings before submitting a new feature request.

  • I have already read Docs page
  • I have already searched existing issues

Feature Request

At present, the way we get toc is to parse the entire article content, this operation is no problem. But if it work with markdown or other renderers together, there will be redundant parsing operations. During the markdown parse, the toc has already been parsed. If we cache them, this will bring better performance

Others

This is an example
master...jiangtj:toc
hexojs/hexo-renderer-marked@master...jiangtj-lab:toc

Result
image

@SukkaW
Copy link
Member

SukkaW commented May 25, 2020

FYI, due to Hexo rendering process (which I still have little idea about it), the helper will be executed twice.

@jiangtj
Copy link
Member Author

jiangtj commented May 25, 2020

the helper will be executed twice.

Helper execution times are related to the number of rendering times in the template engine, I think if the location of the toc call is reasonable, it will only be executed once.

I mentioned this issue because if markown renders can cache the toc, then the toc helper only needs to get the cache instead of parsing the article.

However, this will also make hexo more replicated, and the coupling with the plugin increases

So I don’t know if it should be done this way

@SukkaW
Copy link
Member

SukkaW commented May 25, 2020

@jiangtj

We might need a prop or sorts of things to make plugins contact with each other.

For example, if renderer could store ASTs in a global object. Then toc helper could first read it from the object, then decide if the parse is necessary.

@SukkaW
Copy link
Member

SukkaW commented May 25, 2020

The idea was originally made in #4070, which is now discarded.

@jiangtj
Copy link
Member Author

jiangtj commented May 26, 2020

@SukkaW I tested it, the performance did not seem to improve much, but made the code more complicated. Closed.

@jiangtj jiangtj closed this as completed May 26, 2020
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

2 participants