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

fix: Remove triple parsing of diagrams #4697

Merged
merged 7 commits into from
Aug 11, 2023
Merged

Conversation

sidharthv96
Copy link
Member

@sidharthv96 sidharthv96 commented Aug 3, 2023

📑 Summary

Many diagrams were parsed 2-3 times for each render. Removed that.

📏 Design Decisions

Moved the call to init() after clear().

📋 Tasks

Make sure you

@codecov
Copy link

codecov bot commented Aug 3, 2023

Codecov Report

Merging #4697 (da8112a) into develop (bcb0817) will increase coverage by 26.79%.
The diff coverage is 93.33%.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff              @@
##           develop    #4697       +/-   ##
============================================
+ Coverage    46.03%   72.82%   +26.79%     
============================================
  Files           53      146       +93     
  Lines         6736    14658     +7922     
  Branches        18      562      +544     
============================================
+ Hits          3101    10675     +7574     
- Misses        3635     3851      +216     
- Partials         0      132      +132     
Flag Coverage Δ
e2e 77.98% <85.71%> (?)
unit 46.08% <61.53%> (+0.05%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Changed Coverage Δ
packages/mermaid/src/diagrams/er/erRenderer.js 93.47% <ø> (ø)
.../mermaid/src/diagrams/sequence/sequenceRenderer.ts 62.46% <ø> (ø)
packages/mermaid/src/mermaidAPI.ts 59.79% <0.00%> (+16.17%) ⬆️
packages/mermaid/src/Diagram.ts 66.66% <100.00%> (+26.66%) ⬆️
packages/mermaid/src/diagram-api/diagramAPI.ts 69.62% <100.00%> (+13.92%) ⬆️
.../mermaid/src/diagrams/flowchart/flowRenderer-v2.js 72.64% <100.00%> (ø)
...ges/mermaid/src/diagrams/state/stateRenderer-v2.js 92.94% <100.00%> (ø)

... and 133 files with indirect coverage changes

@sidharthv96
Copy link
Member Author

sidharthv96 commented Aug 3, 2023

Time taken to render diagrams in demos/flowchart.html

Browser Before After Decrease
Chromium 2289.7900001049043 1945.0699999332428 15%
Firefox 1157.3 971.8 16%
Webkit 2626.2 2525.5 3.8%
Before

Chromium


render: 2157.5 ms
render: 2163.2000002861023 ms
render: 2151.5 ms
render: 2160.699999809265 ms
render: 2709.1000003814697 ms
render: 2367.5 ms
render: 2637.7000002861023 ms
render: 2195.1000003814697 ms
render: 2227.4000000953674 ms
render: 2128.199999809265 ms
Average: 2289.7900001049043

Firefox


render: 1245 ms
render: 1133 ms
render: 1161 ms
render: 1150 ms
render: 1167 ms
render: 1137 ms
render: 1151 ms
render: 1154 ms
render: 1125 ms
render: 1150 ms
Average: 1157.3

Webkit


render: 2758 ms
render: 2637 ms
render: 2653 ms
render: 2614 ms
render: 2602 ms
render: 2549 ms
render: 2588 ms
render: 2610 ms
render: 2595.0000000000005 ms
render: 2656 ms
Average: 2626.2
After

Chromium


render: 1963.9000000953674 ms
render: 1891.0999999046326 ms
render: 1998 ms
render: 1934.7999997138977 ms
render: 1982.5 ms
render: 1944.7999997138977 ms
render: 1950.5 ms
render: 1915.5 ms
render: 1911.5 ms
render: 1958.0999999046326 ms
Average: 1945.0699999332428

Firefox


render: 1037 ms
render: 954 ms
render: 1026 ms
render: 943 ms
render: 954 ms
render: 939 ms
render: 973 ms
render: 986 ms
render: 964 ms
render: 942 ms
Average: 971.8

Webkit


render: 2535 ms
render: 2583 ms
render: 2557 ms
render: 2536 ms
render: 2540 ms
render: 2554 ms
render: 2512 ms
render: 2479 ms
render: 2486 ms
render: 2473 ms
Average: 2525.5

Interesting to see Firefox is twice as fast as Chrome for rendering mermaid!

@sidharthv96
Copy link
Member Author

Related

@Yokozuna59
Copy link
Member

Awesome!

I saw some diagrams have init function in it's definition, and it's clearing the DB there, is it related to this PR? i.e., flowDiagram-v2.

@sidharthv96
Copy link
Member Author

Awesome!

I saw some diagrams have init function in it's definition, and it's clearing the DB there, is it related to this PR? i.e., flowDiagram-v2.

Yeah, I noticed that, but didn't want to change too much in this PR. That can be removed and tested in an upcoming flowDB cleanup PR (that I'm working on).

@nirname
Copy link
Contributor

nirname commented Aug 4, 2023

Awesome. What I previously did was only initial cleanup of extra rendering, and you opened a can of warms for sure. Nice excavations.

packages/mermaid/src/Diagram.ts Outdated Show resolved Hide resolved
Copy link
Member

@aloisklink aloisklink left a comment

Choose a reason for hiding this comment

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

Wooo, the performance impact sounds pretty nice!

The only potential issue I see is whether or not this is a BREAKING CHANGE.

In some of the tests, you've removed lines that used to have await mermaidAPI.parse(str1);. Is this something that might break how Mermaid's public API works?

packages/mermaid/src/Diagram.ts Outdated Show resolved Hide resolved
packages/mermaid/src/mermaidAPI.ts Outdated Show resolved Hide resolved
Copy link
Member

@Yokozuna59 Yokozuna59 left a comment

Choose a reason for hiding this comment

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

The only potential issue I see is whether or not this is a BREAKING CHANGE.

In some of the tests, you've removed lines that used to have await mermaidAPI.parse(str1);. Is this something that might break how Mermaid's public API works?

I guess it's not a breaking change. When initializing new diagram using new Diagram(), it runs the parse function async and update the DB, which is exactly what the mermaidAPI do when calling mermaidAPI.parse.

packages/mermaid/src/Diagram.ts Outdated Show resolved Hide resolved
@Yokozuna59
Copy link
Member

After looking at these changes, doesn't that mean that there's no use of text parameter in draw function expect logging what diagram is being rendered with the actual diagram text?

I guess we could add that log call inside the render function with id, something like this:

log.debug(`rendering ${id} diagram\n${text}`);

So maybe now we could remove unnecessary parameters in v11, see #4450 (comment).

Co-authored-by: Alois Klink <alois@aloisklink.com>
Co-authored-by: Nikolay Rozhkov <nironame@gmail.com>
Co-authored-by: Yokozuna59 <u.yokozuna@gmail.com>
@sidharthv96 sidharthv96 self-assigned this Aug 7, 2023
sidharthv96 and others added 2 commits August 8, 2023 00:24
Co-authored-by: Alois Klink <alois@aloisklink.com>
@sidharthv96
Copy link
Member Author

The only potential issue I see is whether or not this is a BREAKING CHANGE.

In some of the tests, you've removed lines that used to have await mermaidAPI.parse(str1);. Is this something that might break how Mermaid's public API works?

I don't think it'll have any external changes visible to the mermaidAPI.parse users.


So maybe now we could remove unnecessary parameters in v11, see #4450 (comment).

Yes, we could! The renderer should not need to know anything regarding the original text. It's only concern should be rendering whatever is in the DB.

Copy link
Member

@aloisklink aloisklink left a comment

Choose a reason for hiding this comment

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

I don't think it'll have any external changes visible to the mermaidAPI.parse users.

In that case, I'll officially approve this PR :)


So maybe now we could remove unnecessary parameters in v11, see #4450 (comment).

Yes, we could! The renderer should not need to know anything regarding the original text. It's only concern should be rendering whatever is in the DB.

Should we make a GitHub issue (or maybe a GitHub Discussion is better) for all of the breaking changes we want in a v11 release?

There are some breaking changes I want to make to Mermaid.JS types :)

@aloisklink
Copy link
Member

Side-note, what label should we give this PR for the Release notes? Type: Bug / Error or Type: Other?

Maybe we should make a new label called Type: Performance, since most JavaScript projects use a different label for performance stuff (e.g. see @commitlint/config-conventional, which uses perf: xxxx for commits that affect performance).

* develop: (59 commits)
  fix!(deps): fix zenuml style leakage. update @zenuml/core to ^3.0.6 to fix the style leakage.
  Update selectSvgElement.ts
  create `Group` type
  Add specialChars in textNoTagsToken, alphaNumToken
  Return Unicode Text to idStringToken definition
  Add underscore to unit test on special Chars
  Revert to old docs concerning quotations marks in string
  Refactor unit tests and remove repetition
  Correct idStringToken definition to include all individual special tokens
  Add unit tests for node ids with special Chars
  Create lychee.toml
  create `selectSvgElement`
  change `svgElem` to `SVG` in `configureSvgSize`
  add `configureSvgSize` in infoRenderer
  run docs:build
  remove info sandbox test case
  Remove replaceAll method in addLink
  Modify HREF token regex to contain space
  Add unit tests for stange node names
  Remove escaped quotes with backslash feature
  ...
@Yokozuna59
Copy link
Member

Should we make a GitHub issue (or maybe a GitHub Discussion is better) for all of the breaking changes we want in a v11 release?

I think we should. We are currently just suggesting stuff in random issues and PRs without collecting and filtering them. It would also help us create a changelog for v11.

@sidharthv96
Copy link
Member Author

sidharthv96 commented Aug 8, 2023

Done: https://github.com/orgs/mermaid-js/discussions/4710
Also updated the next branch, which we could use for the breaking changes.

Copy link
Collaborator

@knsv knsv left a comment

Choose a reason for hiding this comment

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

Good Job @sidharthv96 !

@knsv knsv added this pull request to the merge queue Aug 11, 2023
@sidharthv96 sidharthv96 removed this pull request from the merge queue due to a manual request Aug 11, 2023
@sidharthv96 sidharthv96 merged commit da602ad into develop Aug 11, 2023
21 checks passed
fuxingloh referenced this pull request in fuxingloh/contented Aug 15, 2023
[![Mend
Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
| [mermaid](https://togithub.com/mermaid-js/mermaid) | [`10.3.0` ->
`10.3.1`](https://renovatebot.com/diffs/npm/mermaid/10.3.0/10.3.1) |
[![age](https://developer.mend.io/api/mc/badges/age/npm/mermaid/10.3.1?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![adoption](https://developer.mend.io/api/mc/badges/adoption/npm/mermaid/10.3.1?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![passing](https://developer.mend.io/api/mc/badges/compatibility/npm/mermaid/10.3.0/10.3.1?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/mermaid/10.3.0/10.3.1?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|

---

### Release Notes

<details>
<summary>mermaid-js/mermaid (mermaid)</summary>

###
[`v10.3.1`](https://togithub.com/mermaid-js/mermaid/releases/tag/v10.3.1)

[Compare
Source](https://togithub.com/mermaid-js/mermaid/compare/v10.3.0...v10.3.1)

#### What's Changed

#### Bugfixes

- fix style in contributors section of intro by
[@&#8203;keer4n](https://togithub.com/keer4n) in
[https://github.com/mermaid-js/mermaid/pull/4670](https://togithub.com/mermaid-js/mermaid/pull/4670)
- fix:
[#&#8203;4676](https://togithub.com/mermaid-js/mermaid/issues/4676)
redirect fix by [@&#8203;sidharthv96](https://togithub.com/sidharthv96)
in
[https://github.com/mermaid-js/mermaid/pull/4693](https://togithub.com/mermaid-js/mermaid/pull/4693)
- [#&#8203;2139](https://togithub.com/mermaid-js/mermaid/issues/2139)
Applying user defined classes properly when calculating shape width by
[@&#8203;knsv](https://togithub.com/knsv) in
[https://github.com/mermaid-js/mermaid/pull/4722](https://togithub.com/mermaid-js/mermaid/pull/4722)
- Bug/4645 graph node containing keyword by
[@&#8203;ibrahimWassouf](https://togithub.com/ibrahimWassouf) in
[https://github.com/mermaid-js/mermaid/pull/4657](https://togithub.com/mermaid-js/mermaid/pull/4657)
- fix: Remove triple parsing of diagrams by
[@&#8203;sidharthv96](https://togithub.com/sidharthv96) in
[https://github.com/mermaid-js/mermaid/pull/4697](https://togithub.com/mermaid-js/mermaid/pull/4697)
- resolve info `HTML` and `Document` assignment by
[@&#8203;Yokozuna59](https://togithub.com/Yokozuna59) in
[https://github.com/mermaid-js/mermaid/pull/4514](https://togithub.com/mermaid-js/mermaid/pull/4514)
- fix!(deps): fix zenuml style leakage. by
[@&#8203;danshuitaihejie](https://togithub.com/danshuitaihejie) in
[https://github.com/mermaid-js/mermaid/pull/4705](https://togithub.com/mermaid-js/mermaid/pull/4705)
- Use our prettier config on the `packages/mermaid/src/config.type.ts`
file by [@&#8203;aloisklink](https://togithub.com/aloisklink) in
[https://github.com/mermaid-js/mermaid/pull/4715](https://togithub.com/mermaid-js/mermaid/pull/4715)
- create `ParserDefinition` type by
[@&#8203;Yokozuna59](https://togithub.com/Yokozuna59) in
[https://github.com/mermaid-js/mermaid/pull/4719](https://togithub.com/mermaid-js/mermaid/pull/4719)
- standardized `error` diagram by
[@&#8203;Yokozuna59](https://togithub.com/Yokozuna59) in
[https://github.com/mermaid-js/mermaid/pull/4718](https://togithub.com/mermaid-js/mermaid/pull/4718)

#### Documentation

- Docs: Directives not needed in new diagrams as yaml formatter does
this for all new diagrams by
[@&#8203;Incognito](https://togithub.com/Incognito) in
[https://github.com/mermaid-js/mermaid/pull/4688](https://togithub.com/mermaid-js/mermaid/pull/4688)
- Docs: add latest blog post by
[@&#8203;huynhicode](https://togithub.com/huynhicode) in
[https://github.com/mermaid-js/mermaid/pull/4668](https://togithub.com/mermaid-js/mermaid/pull/4668)
- Lychee config by [@&#8203;mmorel-35](https://togithub.com/mmorel-35)
in
[https://github.com/mermaid-js/mermaid/pull/4699](https://togithub.com/mermaid-js/mermaid/pull/4699)
- Syntax Update CONTRIBUTING.md by
[@&#8203;soomrozaid](https://togithub.com/soomrozaid) in
[https://github.com/mermaid-js/mermaid/pull/4713](https://togithub.com/mermaid-js/mermaid/pull/4713)

#### Chores

- chore(deps): update all minor dependencies (minor) by
[@&#8203;renovate](https://togithub.com/renovate) in
[https://github.com/mermaid-js/mermaid/pull/4682](https://togithub.com/mermaid-js/mermaid/pull/4682)
- build(deps-dev): bump json5 from 2.2.1 to 2.2.3 by
[@&#8203;dependabot](https://togithub.com/dependabot) in
[https://github.com/mermaid-js/mermaid/pull/4685](https://togithub.com/mermaid-js/mermaid/pull/4685)
- build(deps): bump
[@&#8203;braintree/sanitize-url](https://togithub.com/braintree/sanitize-url)
from 6.0.0 to 6.0.1 by
[@&#8203;dependabot](https://togithub.com/dependabot) in
[https://github.com/mermaid-js/mermaid/pull/4686](https://togithub.com/mermaid-js/mermaid/pull/4686)
- build(deps-dev): bump vite from 4.3.3 to 4.3.9 by
[@&#8203;dependabot](https://togithub.com/dependabot) in
[https://github.com/mermaid-js/mermaid/pull/4687](https://togithub.com/mermaid-js/mermaid/pull/4687)
- chore(deps): update all patch dependencies (patch) by
[@&#8203;renovate](https://togithub.com/renovate) in
[https://github.com/mermaid-js/mermaid/pull/4681](https://togithub.com/mermaid-js/mermaid/pull/4681)
- chore: ts-ignore comment was misleading, JISON doesn't support types
by [@&#8203;Incognito](https://togithub.com/Incognito) in
[https://github.com/mermaid-js/mermaid/pull/4689](https://togithub.com/mermaid-js/mermaid/pull/4689)
- chore(deps): unpin the dompurify dependency by
[@&#8203;djadmin](https://togithub.com/djadmin) in
[https://github.com/mermaid-js/mermaid/pull/4677](https://togithub.com/mermaid-js/mermaid/pull/4677)
- build(deps-dev): bump pnpm from 8.3.1 to 8.6.8 by
[@&#8203;dependabot](https://togithub.com/dependabot) in
[https://github.com/mermaid-js/mermaid/pull/4692](https://togithub.com/mermaid-js/mermaid/pull/4692)

#### New Contributors

- [@&#8203;keer4n](https://togithub.com/keer4n) made their first
contribution in
[https://github.com/mermaid-js/mermaid/pull/4670](https://togithub.com/mermaid-js/mermaid/pull/4670)
- [@&#8203;djadmin](https://togithub.com/djadmin) made their first
contribution in
[https://github.com/mermaid-js/mermaid/pull/4677](https://togithub.com/mermaid-js/mermaid/pull/4677)
- [@&#8203;danshuitaihejie](https://togithub.com/danshuitaihejie) made
their first contribution in
[https://github.com/mermaid-js/mermaid/pull/4705](https://togithub.com/mermaid-js/mermaid/pull/4705)
- [@&#8203;soomrozaid](https://togithub.com/soomrozaid) made their first
contribution in
[https://github.com/mermaid-js/mermaid/pull/4713](https://togithub.com/mermaid-js/mermaid/pull/4713)

**Full Changelog**:
mermaid-js/mermaid@v10.3.0...v10.3.1

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined),
Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you
are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Mend
Renovate](https://www.mend.io/free-developer-tools/renovate/). View
repository job log
[here](https://developer.mend.io/github/levaintech/contented).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNi40MC4zIiwidXBkYXRlZEluVmVyIjoiMzYuNDMuMiIsInRhcmdldEJyYW5jaCI6Im1haW4ifQ==-->

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
@Yokozuna59 Yokozuna59 deleted the sidv/fixTripleParsing branch August 15, 2023 17:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants