swift-markdown-ui icon indicating copy to clipboard operation
swift-markdown-ui copied to clipboard

Severe hang when rendering a short markdown string with 6-level nested bullet points

Open hsinlei opened this issue 1 year ago • 1 comments
trafficstars

Thank you for contributing to MarkdownUI!

Before you submit an issue, please complete the report with all the relevant details for your bug and go through every item in the checklist.

Describe the bug Severe hang (1-2s) when rendering a relatively short markdown string (~hundreds of characters) with nested bullet points (6 levels).

Checklist

  • [x] I can reproduce this issue with a vanilla SwiftUI project.
  • [x] I can reproduce this issue using the main branch of this package.
  • [x] This bug hasn't been addressed in an existing GitHub issue.

Steps to reproduce Explanation of how to reproduce the incorrect behavior. This could include an attached project, a link to code, or a Markdown-formatted text exhibiting the issue.

  1. Clone this minimal demo project
  2. Build and run it, tap the "Go" navigation link, and observe a 1-2s UI freezing before the view transition
  3. Profile and record the run using XCode Instruments Timing Profiling tool, tap the "Go" navigation link, and observe "Severe Hang" and 100% CPU usage

Expected behavior Ideally no hang from rendering such a short markdown string. If heavy computation can't be easily optimized out, move the computation off of the main UI thread to avoid hangs.

Screenshots Screenshot 2024-04-20 at 10 54 23 AM

Version information

  • MarkdownUI: 2.3.0
  • OS: iOS 17.4.1
  • Xcode: 15.2

Additional context

  • Looks like it has to do with the deeply nested bullet points (i.e. 6 levels)
  • Un-nesting the deepest level of bullets (i.e. moving them to become siblings of their original parent bullets) mitigates the Severe Hang into just Hang
  • Further un-nesting (i.e. reducing from 5 levels to 4 levels nested bullets) results in no Hang at all

hsinlei avatar Apr 20 '24 21:04 hsinlei

Thanks for reporting. I will take a look as soon as I have some spare time.

gonzalezreal avatar Apr 23 '24 06:04 gonzalezreal