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

v2.13+: Syntax highlighting slowdown #2469

Closed
4 tasks done
riveravaldez opened this issue Nov 6, 2024 · 27 comments · Fixed by #2487
Closed
4 tasks done

v2.13+: Syntax highlighting slowdown #2469

riveravaldez opened this issue Nov 6, 2024 · 27 comments · Fixed by #2487

Comments

@riveravaldez
Copy link

⚠️ This issue respects the following points: ⚠️

  • This is a bug. Not a question or feature request.
  • The topic is not already reported at Issues. (I've searched it).
  • Markor is up to date. See Releases for the latest version. Updates are available from F-Droid and GitHub.
  • The bug is still present in the latest development version (git master). (Please download and try the test version of Markor, named Marder. Don't worry; Markor and Marder appear as completely separate applications. You can install both side-by-side, and Markor settings are not touched. In case the issue is resolved there, you don't need to create a bug report. The change will be part of the next Markor update.)

Description

Hi, I'm noticing in last version that: Settings → Edit mode → Bigger headings:
[Enabled] Edition becomes slow.
[Disabled] Edition returns to normality.

Noticeable in large .md files, with File settings → Syntax highlighting: Enabled. (Syntax highlighting: Disabled, also fix the issue.)
Apparently, more notorious when using system's auto-corrector or adding dots at the end of words?
Let me know if there's something I could do to help check this.
Thanks a lot for everything! <3

Steps to reproduce

  1. Enable "Syntax highlighting"
  2. Enable "Bigger headings"
  3. Edit a large text file (.md) with various levels of headings

Information

Android version: 10 (LineageOS version: 17.1)
Device: Moto E LTE 2015 (surnia)
App Version: 2.13.0 (155) - Added on 30/10/2024

Source

F-Droid

Format / File type

Markdown

Additional info / Log

-
@gsantner
Copy link
Owner

gsantner commented Nov 6, 2024

Correct, and that is why it is disabled by default.

Android Text components have a notable penalty on dynamic font sizes.

@riveravaldez
Copy link
Author

Hi, thanks a lot for the quick reply and explanation.
Sorry for the lack of detail: I've being using Bigger headings: Enabled for years, and noticed an increased amount of delay/slowness with this last version of Markor/Marder compared to the previous version (I guess it was 2.12.5 (154)).
Maybe it's worth a check. Sorry if I'm wrong.
Kind regards and thanks a lot!

@gsantner
Copy link
Owner

gsantner commented Nov 15, 2024

hey @harshad1 ,

insight: there seems to be some performance degrade in the latest release.
Not sure exactly why, but people tell only about v2.13.0 and that it worked better before.

riveravaldez explcitly mentions bigger headings, but not seems specific to it, rather happens to be because it's one of the most tricky ones.

image

image

image that one looks like infinite recursion

image

image

image

I could only find the heading one and otherwise generic references. As the header regex wasn't changed recently it seems pretty safe to say that it's in something in the highlighting processing chain and not some specific slow regex or font/span operation

@gsantner gsantner changed the title 'Bigger headings' enabled: slows edition (on long .md files) v2.13.0: Syntax highlighting slowdown Nov 15, 2024
@gsantner gsantner reopened this Nov 15, 2024
@riveravaldez
Copy link
Author

riveravaldez commented Nov 16, 2024

riveravaldez explcitly mentions bigger headings, but not seems specific to it, rather happens to be because it's one of the most tricky ones.

Indeed, precisely. Seems to me that Bigger headings just make it worse, but the problem arises (or disappears) between enabling (or disabling) Syntax highlighting. With that disabled Markor works perfectly. Enabling it makes slowness to start. At least on long .md files.

Best regards and thanks a lot.

@harshad1
Copy link
Collaborator

I recently added logic to make highlighting happen on its own thread.

This should have been a performance improvement overall

Will investigate

@harshad1
Copy link
Collaborator

Note that highlighting and everything is going to be slow on very long files.

Android's edit text is very inefficient when a lot of spans are present we have a system in markor which adds and removes spans as you scroll to reduce the total number present at any one time.

Bigger headings (and todo.txt) have spans which don't work well with this so we manage these spans separately and do not adjust them dynamically. Both these cases will always be slower.

@harshad1
Copy link
Collaborator

@riveravaldez could you share a sample file and some more information on when you see the slowdown (typing? Scrolling? Typing at the top vs the bottom of the file?)

@clach04
Copy link

clach04 commented Nov 29, 2024

Also also issue with plain txt files, turns out syntax highlights are enabled for default for .txt as well. Cross reference #2478

@clach04
Copy link

clach04 commented Nov 29, 2024

Note that highlighting and everything is going to be slow on very long files.

Android's edit text is very inefficient when a lot of spans are present we have a system in markor which adds and removes spans as you scroll to reduce the total number present at any one time.

Bigger headings (and todo.txt) have spans which don't work well with this so we manage these spans separately and do not adjust them dynamically. Both these cases will always be slower.

Possibly worth opening a new issue/discussion; what do you think about adding options/features to handle this from a user perspective. For example:

  1. Disable syntax highlighting for files larger than a user entered size. Maybe with an out of box default of 75Kb(slightly arbitrary number)
  2. Have an on screen button to toggle syntax highlights on/off, there is a menu item when editing but it takes a few (three) clicks to get to.

Most of my files are small, I have a small handful of larger files so I would definitely like syntax highlights on unless it's a large file. Rather than off then enable. The Todo.txt syntax highlighting is awesome!

Hopefully threading change @harshad1 is looking at will have a positive impact 🤞

@gsantner
Copy link
Owner

You should not have to worry about it. Also in the past not. It just not works well currently.

You also should not need to constantly toggle it off and on, so its fine if it not bloats the immedate screen.

@riveravaldez
Copy link
Author

Hi, sorry I didn't got the time to reply properly and with information.
Just to clarify and in case it's useful: the issue seems to be fixed in v2.13.1 (156), at least I have the impression Markor is working as usual.
Thanks a lot for that!
Gonna try to answer the other questions soon. Kind regards!

@otzoran
Copy link

otzoran commented Dec 2, 2024

hi, thanx for this gem of app.

the issue seems to be fixed in v2.13.1 (156)

On a galaxy S7 (vanilla, installed from Google Store) I experience this slowdown since ~2 months with files smaller. No recent improvement, current version is v2.13.1 (no build number, taken from Settings/Apps).

PS I didn't find where in Markor the version is stated.

@gsantner
Copy link
Owner

gsantner commented Dec 2, 2024

On the More tab.

@otzoran
Copy link

otzoran commented Dec 3, 2024

@gsantner thank you for the quick reply. I just installed Markor v2.12.2 (code 151):

  • picked this version since it works flawlessly on another device (albeit much more powerful than the S7)
  • uninstalled from Google Play
  • downloaded v2.12.2 from the Releases page, adb install
  • restored settings.json

Performance is satisfactory and back to normal with both Syntax highlighting and Bigger headings turned on.

RE version in the More tab: may I suggest the usual, expected location, at the bottom of the Settings pane.

@harshad1
Copy link
Collaborator

I am going to mark this as done. Please post if an issue appears again.

@otzoran
Copy link

otzoran commented Dec 23, 2024

I am going to mark this as done. Please post if an issue appears again.

dear @harshad1
As reported above, the slowdown issue is manifested in the 2.13.x versions. I had to revert to v2.12.2 (code 151) to regain normal performance.
I also tested markor-v154-2.12.5 and performance is satisfactory, so the slowdown was introduced between v2.12.5 and v2.13.0

the problem isn't solved, please don't close

@gsantner gsantner reopened this Dec 23, 2024
@gsantner gsantner changed the title v2.13.0: Syntax highlighting slowdown v2.13.0+: Syntax highlighting slowdown Dec 23, 2024
@gsantner gsantner changed the title v2.13.0+: Syntax highlighting slowdown v2.13+: Syntax highlighting slowdown Dec 23, 2024
@harshad1
Copy link
Collaborator

Ah ok. I will take another look..

@riveravaldez
Copy link
Author

dear @harshad1 As reported above, the slowdown issue is manifested in the 2.13.x versions. I had to revert to v2.12.2 (code 151) to regain normal performance. I also tested markor-v154-2.12.5 and performance is satisfactory, so the slowdown was introduced between v2.12.5 and v2.13.0

Hi, sorry to bother, I'm using Markor from F-Droid, are you also or your version comes from Google Play Store?

More in general: both versions are the same? 🤔

Best regards to everybody, 🍻

@gsantner
Copy link
Owner

There is nearly no difference. On Google Play installation of APK is not allowed from Markor file manager, because Google disallows it (well, other filemanagers are allowed to, but Markor is not according to them).

For syntax highlighting or editing there should is no different code.

@otzoran
Copy link

otzoran commented Dec 23, 2024

@riveravaldez

I'm using Markor from F-Droid ...

Assuming the question was directed to me:

  • Initially I installed from Google's Play Store
  • The v2.12 APKs were downloaded from Markor's Releases page
  • Installed using either adb install (from mac) or locally using Cx File Explorer

@otzoran
Copy link

otzoran commented Dec 23, 2024

@gsantner thank you for the quick response.

For syntax highlighting or editing there should is no different code

Something slows down Syntax Highlighting and Bigger Headings (enabled together or separately). It feels like excessive resource consumption: CPU, RAM or both.
@harshad1 mentioned spans above, maybe something in the way you partition the file has changed and this has the impact on performance.

@harshad1
Copy link
Collaborator

@riveravaldez

Could you try the version from this branch and see if he helps

#2487

@riveravaldez
Copy link
Author

riveravaldez commented Dec 30, 2024

Hi, @harshad1 , everything is working fine here (check, #2469 (comment) ), I was checking just to verify if it wasn't some particular issue for Google Play Store users. My version from F-Droid is working normally (or even better with some of the new improvements).
Best regards, thanks a lot! <3

@harshad1
Copy link
Collaborator

@otzoran could you check too

@gsantner gsantner linked a pull request Jan 2, 2025 that will close this issue
gsantner added a commit that referenced this issue Jan 2, 2025
…er navigation (PR #2487 closes #2469 #2484)

* Keypress handler
* Restored option, fixed duplicate calls to loadFolder on resume
* Made some small changes for highlighting performance
---------

Co-authored-by: Gregor Santner <[email protected]>
@otzoran
Copy link

otzoran commented Jan 2, 2025

hi @harshad1
sorry for the delay

@otzoran could you check too

guessing you refer to the build artifact of CI #1171: Commit c897359 on your branch?
if so I'll check tomorrow, if not please link to an apk

best

@otzoran
Copy link

otzoran commented Jan 3, 2025

hi @harshad1, @gsantner

downloaded net.gsantner.markor-v156-2.13.1-flavorAtest-debug.apk, (as pointed out in my prev. post).
uninstalled 2.12.5
installed Marder, identified with build info:

Package: net.gsantner.markor_test
Version: v2.13.1-1744 (250102)
Flavor: Atest (debug)
Build date: 2025-01-02T17:44Z
ISource: Sideloaded
VCS Hash: c89735960a92244a17d6b849a201a3a6a4b8db38
VCS Msg: Reformat code

Config: restored my Markor json

Test Results: Fine, no slowdown with Syntax Highlighting and Bigger Headings (enabled together or separately) on a file ~300KB that had the issues reported above.

well done, thanx a lot

@harshad1
Copy link
Collaborator

harshad1 commented Jan 3, 2025

👍

Just note that bigger headings are always going to cause some slowdown if there are a lot of them. You can probably edit a file 5x as big with bigger headings turned off.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants