Skip to content

Limitation on code block count and code length. #2

@yuliu

Description

@yuliu

As I've stated in MyBB's Discord, the right thing to be concerned is the length of a code block or the total length of code blocks in a page for performance when rendering by client side JS. And limiting the code block count is not ideal.

Turn to this page: https://community.mybb.com/thread-225028.html , the first code block has ~1.5k lines, which slows down the highlighting and makes browser freeze on mobile devices.

I read from code, there are two performance related limits:

  1. prismjs_code_formatter_heavy_count (via): currently 10 blocks. (maybe only 9 blocks are permitted before stopping rendering?)
  2. prismjs_code_formatter_heavy_length (via): currently 50000 lines.

I don't know if the length (2nd limit) is applied on each code block or all code blocks. Ideally, the latter one is preferred.

Take GitHub for example, it doesn't prevent any code from rendering by the number of code blocks or code length. Viewing large code pages in GitHub from mobile devices will possibly have freezing problems.

I don't think it's the site's fault for rendering the whole page of codes, but won't say the user has to bear this as well. A better way, IMO, to deal with it is either:

  • Simply set different limits for desktop and mobile devices, but it's difficult to maintain in future.
  • Carefully tune the limitation for both code block count & length (probably the code block count could be removed), and show a switch on current page for turning highlighting back on if the script decides to turn some feature off.

For me, the second one is better, I think.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions