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

Enhance #80

Merged
merged 13 commits into from
Oct 10, 2020
Merged

Enhance #80

merged 13 commits into from
Oct 10, 2020

Conversation

Altai-man
Copy link
Member

First part of changes. Second will be focused on adding some necessary features, while this one is focused on preparations and making the code more factored.

There is no need for different candidates for Array and Pod::Block
if the implementation is the same. Create a single candidate for the
two types where `load` call is necessary and use nextwith to pass
the execution there. This makes code shorter and easier to think about,
while not losing a lot in readabilty.
Titlecase suggests type, while in fact we have a routine.
Also, use a more modernand hopefullly robust code style,
for now for 012-multi.t only.
Over the years, code style became a bit inconsistent with
different styling of spacing, indentation and such tiny details.
This commit makes the style more unified, thus encouraging
positive changes and making it easier for the reader to digest.
For now, this one looks like a cosmetic change and
OOP cargo cvlting, as things Just Work in a procedural style
and there is no need for the pesky classes.
However, having data hidden allows us to reason clearer
about what code works with what.
While it might sound ephemerical enough not to bother,
this also allows a much easier renderer extending for our clients.
No big need for all the multis, golf Pod::Raw calculation as well.
Prior this, the code gathered all the headers and rendered them into text in place.
While this is not really wrong, it is not future-proof, because actual content (TOC structure)
is tied to its presentation (particular HTML) and if the user wants to add a mere class or a wrapper
div, everything, including heading gathering logic, must be re-implemented, because do-toc sub
is not extendable.
So, here we introduce TOC::Calculator which has `calculate`, `render` and `render-heading` methods.
First one calculates a structure, representing the TOC of the $pod in question and two other
solely do rendering, thus making it easier to extend and digest. Also, increase test coverage a bit.
@Altai-man Altai-man marked this pull request as draft September 18, 2020 08:22
@JJ
Copy link

JJ commented Sep 18, 2020

Thanks!

@Altai-man
Copy link
Member Author

Altai-man commented Sep 18, 2020

Please review.

I also observe a surprising (to me) noticeable slowdown, e.g. 012-multi run for 10 times here takes around 2.7-2.8 seconds, but version on master takes about 2.1 (this can be explained by the fact that amount of code run by the test differs, but still even if you run )time prove --jobs=4 -e "raku -Ilib" t/ without 012-multi test, version on master is always faster.

Seems like using given/when instead of multi by type gives quite a penalty. Can anyone skilled with performance see if we can make it at least as fast as it was again?

@lizmat
Copy link

lizmat commented Sep 18, 2020

Isn't the $html ~~ m:g just an expensive way of doing .contains ?

@Altai-man
Copy link
Member Author

@lizmat it is, overall some tests are suboptimal here, but it is used only on testing, so does not make the actual code perf worse, I think.

@JJ
Copy link

JJ commented Sep 18, 2020 via email

@antoniogamiz
Copy link

Mustache was incorporated a long time ago, but it was not really used. The problem was the parsing phase of mustache, which was solved by @softmoth.

The current version of Documentable takes (more or less) the same time than the older.

- Make node renderer overloadable
- Make TOC renderer overloadable
- Make do-footnotes method public, thus overloadable
- Export a couple of universally used subs

Tiny tweaks:

- Make names in assemble-list-items more readable
- Tweak heading handler logic a bit
- Remove `Pod::To::HTML` module wrapper, let's see if it breaks anything
While we are striving to preserve backward compatibility everywhere,
a version bump fulfills its purposes here.
@JJ
Copy link

JJ commented Sep 19, 2020

Still in draft state? Or is it ready for review?

@Altai-man
Copy link
Member Author

For now I have all the features I currently need, so can be reviewed, yes.

@Altai-man Altai-man marked this pull request as ready for review September 19, 2020 12:22
@Altai-man
Copy link
Member Author

For reviewers: I suggest going commit by commit, instead of a full diff, which became cumbersome due to file renaming. I tried to make commit messages nice enough as well.

@Altai-man
Copy link
Member Author

Anyone?

Copy link

@JJ JJ left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's tested and everything, so it can only help.

@@ -1,10 +1,17 @@
use Test; # -*- mode: perl6 -*-
use Test;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really need the mode lines, but, hey, not a big deal.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should switch to .rakutest extensions then?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably.

@JJ JJ merged commit 7efefde into master Oct 10, 2020
@JJ
Copy link

JJ commented Oct 10, 2020

Did you do any kind of benchmark?

@JJ
Copy link

JJ commented Oct 10, 2020 via email

@Altai-man
Copy link
Member Author

Did you do any kind of benchmark?

Run test suite and it got somewhat slower, but I also increased number of tests somewhat, so hard to judge. What I know is that I generate pages for the website using this branch and it is pretty okay for me. Not sure how it would react on building whole documentation at once, but we can hopefully resolve it together should an issue arise.

@lizmat
Copy link

lizmat commented Oct 10, 2020

FWIW, I did a profile on converting one of my more extensively documented modules: most of the time is spent in Str!rakufy (about 34%), then in QRegex!protoregex (11%) and then a whole lot of grammarly things in Template::Mustache.

Barring some magical insights, Str.rakufy is already pretty much maximally optimized.

@Altai-man
Copy link
Member Author

Altai-man commented Oct 11, 2020

Thanks for the insight, @lizmat !

and then a whole lot of grammarly things in Template::Mustache

I opened #82 because in my tests Cro::WebApp templates are faster than Template::Mustache (not by a lot, about 2x improvement), but during original design mustache templates were quite tightly baked in, so ability to use custom engines should be added very carefully not to break existing tools.

I am also very pleased to note that Pod manipulation and Documentable::Registry is fast enough (though can be made faster, I suspect, as the code apperars to be as suboptimal in some places).

@JJ
Copy link

JJ commented Oct 26, 2020

This PR might also need to be reverted. We really need more extensive tests for this module, including the fact that render needs to be called as a subroutine or a class method, besides an instance method.

@Altai-man
Copy link
Member Author

This PR might also need to be reverted. We really need more extensive tests for this module, including the fact that render needs to be called as a subroutine or a class method, besides an instance method.

No need if existing issues will be fixed.

@JJ JJ mentioned this pull request Oct 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants