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

Any way to speed up loading large files/files with long lines? #2500

Open
4 tasks done
ravilov opened this issue Jan 5, 2025 · 28 comments
Open
4 tasks done

Any way to speed up loading large files/files with long lines? #2500

ravilov opened this issue Jan 5, 2025 · 28 comments

Comments

@ravilov
Copy link

ravilov commented Jan 5, 2025

⚠️ This issue respects the following points: ⚠️

  • This is a enhancement/feature request. Not a bug or question.
  • 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 wanted feature/enhancement is not 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's settings are not touched. If your desired feature is present, you don't need to open this issue. The change will be part of the next Markor update.)

Description

I have several Markdown files with embedded images (as base64 data: streams). Markor takes very long time loading those, and often even freezes/crashes. Interestingly, this only seems to happen on initial load - if it manages to load the file, then switching between VIEW and EDIT is quite speedy. I suspect this has to do with very long lines in the document, but I'm not sure. I tried renaming the MD to TXT, but that didn't help any with loading. Any way to tackle this?

Information

Android version: 14
Device: Samsung A53
App Version: 2.13.1 (156)

Source

F-Droid

Format / File type

Not specific

@harshad1
Copy link
Collaborator

harshad1 commented Jan 5, 2025

Try disabling highlighting?

@ravilov
Copy link
Author

ravilov commented Jan 5, 2025

Already disabled.

@gsantner
Copy link
Owner

gsantner commented Jan 5, 2025

Then nothing should help out of the box in current state.
Maybe contributing some improvements does, but generally Androids Text components are quite sensitive to such content.

@ravilov
Copy link
Author

ravilov commented Jan 5, 2025

I don't know. I have a feeling the slowdown happens at load/parse time, before the content hits any Android components. Notice that once the file finally loads and shows up, switching back and forth between VIEW and EDIT is actually seamless, even with edits and changes to the file.

Sadly I am currently not in a position to try and tackle this myself, or else I'd probably give it a shot.

@gsantner
Copy link
Owner

gsantner commented Jan 5, 2025

EditText.setText() and reading/concatting string sure are taking time

@ravilov
Copy link
Author

ravilov commented Jan 5, 2025

Hmm, I'm guessing you're using the same EditText for the entire "session" of working on a document, including VIEW/EDIT transitions. So just the initial .setText() takes forever. That would make sense.

At the same time, I have this file manager, it comes with a built-in text editor, and when I rename the same document from MD to TXT and open it with that, it loads up in a second. How come? I'm assuming it's also just using the standard Android EditText, it sure looks like one.

I have all the "fancy" stuff in Markor (highlight, line numbers) turned off, so I would think it should be about the same workload...

@harshad1
Copy link
Collaborator

harshad1 commented Jan 6, 2025

Can you post a sample file?

@ravilov
Copy link
Author

ravilov commented Jan 6, 2025

Sure, here it is.

sample.zip

@harshad1
Copy link
Collaborator

harshad1 commented Jan 6, 2025

99% this is EditText being slow at layout for large files.

If you disable line wrapping it gets about 2x faster.

@ravilov
Copy link
Author

ravilov commented Jan 6, 2025

My line wrapping is already disabled. I'd hate to see the performance if it wasn't disabled then... 🙁

Still baffled at how this other file manager does it so snappily. It even has wrapping enabled and no way to disable it (its editor is pretty simple). I was using the same file in both.

@gsantner
Copy link
Owner

gsantner commented Jan 6, 2025

As you speak about filemanager, is it really mainly about the EDITOR or are you speaking about some file browser file listing also?

@ravilov
Copy link
Author

ravilov commented Jan 6, 2025

It's the built-in text editor that gets launched when you tap on a file in the manager. File listing works just fine in both Markor and the file manager.

BTW the file manager I keep mentioning is Solid Explorer.

@harshad1
Copy link
Collaborator

harshad1 commented Jan 6, 2025

I tried a couple text editors and they are all at least as slow as markor.

If you can find an open source editor which is fast, I can look into what they do

@ravilov
Copy link
Author

ravilov commented Jan 7, 2025

Bill Farmer's Notepad is quite fast. Just tried it with this same document. It's even capable of rendering Markdown into a local HTML file and starting a web browser to show it.

@harshad1
Copy link
Collaborator

harshad1 commented Jan 7, 2025

@ravilov
Copy link
Author

ravilov commented Jan 7, 2025

Yep, I noticed. Basically the entire editor UI is implemented in this one class. Eventually it does just come down to EditText.setText(), although from an AsyncTask. So who knows. Either way, good luck!

Worth mentioning, it sets the EditText content to "loading..." while loading the file, but I only know this from reading the source. With this particular document at least, it's fast enough that I don't even see the message in practice.

@harshad1
Copy link
Collaborator

Playing around with Bill Farmer's editor I get the same result as we do with markor. It takes a long time to lay out the file if wrapping is turned on.

@ravilov
Copy link
Author

ravilov commented Jan 14, 2025

Understandable I guess, but keep in mind wrapping was always off in Markor for me, yet it still takes ages (and in fact crashes after a while most of the time). If you could get it to be faster at least with wrapping off, that would already be an improvement.

To be honest, I never even tried Bill's Notepad with wrapping on, since I don't have wrapping on in Markor anyway.

@harshad1
Copy link
Collaborator

What phone do you have?

@harshad1
Copy link
Collaborator

On my device it takes ~2s for the file to load without wrapping on

@ravilov
Copy link
Author

ravilov commented Jan 15, 2025

What phone do you have?

Screenshot
😉

On my device it takes ~2s for the file to load without wrapping on

Is that Markor or Bill's Notepad?
With the sample document I uploaded?

@harshad1
Copy link
Collaborator

Markor. I have a pixel 7 pro.

@ravilov
Copy link
Author

ravilov commented Jan 16, 2025

I may have discovered something.

If I load up this large document in Markor directly in EDIT mode, it indeed loads up practically instantly. It even renders fast when I then switch to VIEW. However, I have always had "prefer view mode" option enabled. With that turned on, if I open the document straight from the file selector, then it suddenly takes ages.

I bet you have your Markor set up to go into EDIT first.

So how come going straight to EDIT and then VIEW works blazingly fast, yet trying to go straight to VIEW is so painstakingly slow? Hopefully there is some part of this particular chain that can be sped up. I really do prefer to mostly view my documents as a sort of reference material, editing is considerably more rare for me.

@harshad1
Copy link
Collaborator

I can reproduce this and it is strange indeed. Will investigate

@harshad1
Copy link
Collaborator

@ravilov can you test this? #2509

This is not necessarily the correct solution, but it seems to help

@ravilov
Copy link
Author

ravilov commented Jan 16, 2025

Glad you were able to reproduce. Means I'm not entirely crazy. 🙂

Not sure what I am to test though? Is there a precompiled version with this PR merged in? Unfortunately I can't compile stuff myself right now.

@harshad1
Copy link
Collaborator

https://github.com/gsantner/markor/actions/runs/12804106180/artifacts/2439195070

You'll get a zip which has an apk inside it. The apk will install as 'Marder' alongside your existing Markor

@ravilov
Copy link
Author

ravilov commented Jan 16, 2025

Got I. Yeah, definitely much much faster. Loads the document in VIEW mode in a second or two, versus many minutes before.

Not sure how your changes improve the performance so much (how is setting views to INVISIBLE instead of GONE better? what views are those even?), but I don't really need to know, lol.

If you leave it this way, that's already a huge improvement, but as you indicated, it might be worth figuring out if this is really the best solution. Plus, IMO, it might be worth reworking the loader so it loads in the background while showing some spinning animation, instead of hogging the UI and making it look like it froze (if only briefly with your latest changes). But again, your call. I'm happy to just take the improvement you just made.

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

No branches or pull requests

3 participants