Skip to content

Conversation

@harshad1
Copy link
Collaborator

In this PR I have made the initialization of several components a little faster.

Having really fast launch times makes the experience of using markor nicer.

@harshad1 harshad1 changed the title [WIP] Faster start times Faster start times Dec 2, 2025
* This Activity exists solely to launch activities with the correct intent
* it is necessary as widget and shortcut intents do not respect MultipleTask etc
*/
public class OpenFromShortcutOrWidgetActivity extends MarkorBaseActivity {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

MarkorBaseActivity does some extra work here which is unnecessary

startLine = intent.getIntExtra(Document.EXTRA_FILE_LINE_NUMBER, -1);
} else if (intentData != null) {
final String line = intentData.getQueryParameter("line");
startLine = GsTextUtils.tryParseInt(line, -1);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Bugfix to how the start line and start in preview interact


private HighlightingEditor _hlEditor;
private WebView _webView;
private ViewStub _webViewStub;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The webview is the heaviest view in the document fragment. This loads it lazily when necessary

_lineNumbersView.setup(_hlEditor);
_lineNumbersView.setLineNumbersEnabled(_appSettings.getDocumentLineNumbersEnabled(_document.path));

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && _appSettings.getSetWebViewFulldrawing()) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

same code moved into block which is called when webview is actually required and loaded

_hlEditor.setMinHeight(height);
}
});
_verticalScrollView.addOnLayoutChangeListener((v, left, top, right, bottom, oldLeft, oldTop, oldRight, oldBottom) -> ensureMinHeight.run());
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Listening to a scrollview layout change instead of a global layout change

// Setup viewpager
_viewPager.setAdapter(new SectionsPagerAdapter(getSupportFragmentManager()));
_viewPager.setOffscreenPageLimit(4);
_sectionsAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

When main activity is loaded we do not load not shown tabs immediately.

Instead we load them lazily.

After tabs are loaded, they are cached by the adapter

public void hideKeyboard() {
_cu.showSoftKeyboard(this, false, _quicknote.getEditor());
_cu.showSoftKeyboard(this, false, _todo.getEditor());
if (_quicknote != null) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

These fragments may not be loaded

final boolean isImage = m.group(1) != null;
final String link = m.group(3);
return new Link(m.group(2), link == null ? null : link.trim(), isImage, start, end);
final String link = GsTextUtils.decodeUrl(m.group(3));
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Unrelated fix for how file links with spaces are parsed

%20 now converted to and from space more correctly

final File sel = currentSelection.iterator().next();
final File file = _filesystemViewerAdapter.resolveVirtualFile(sel);
final String title = GsFileUtils.getFilenameWithoutExtension(sel);
_cu.createLauncherDesktopShortcut(getContext(), file, title);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Correctly resolving shortcuts to special folders

}

if (!dest.isFile() && GsTextUtils.endsWith(sb, File.separator)) {
if (GsTextUtils.endsWith(sb, File.separator)) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

trailing separator on file vs folder

#Thu Dec 02 03:48:33 CET 2021
distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.13-bin.zip
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I had to update gradle to get this to work on my new laptop

final foldername = dir.name
if (foldername.startsWith('values-') && !dir.absolutePath.contains("build" + File.separator + "intermediates") && !foldername.matches(".*values-((.*[0-9])|(land)|(port)).*")) {
dir.eachFile { file ->
if (file.name.toLowerCase().endsWith(".xml") && file.getText('UTF-8').contains("<string")) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Changes needed to get the build working

@harshad1
Copy link
Collaborator Author

harshad1 commented Dec 2, 2025

@gsantner This is ready for review

@harshad1
Copy link
Collaborator Author

harshad1 commented Dec 9, 2025

@guanglinn Would you be willing to review this?

@guanglinn
Copy link
Contributor

guanglinn commented Dec 11, 2025

@guanglinn Would you be willing to review this?

I'm willing to review it, but may provide limited suggestions based on my limited understanding of Markor and Android. 😌

@harshad1
Copy link
Collaborator Author

I'm willing to review it, but may provide limited suggestions due to my limited understanding of Markor and Android. 😌

This is pretty much the only Java and Android project I work on as well. I'll take any feedback

@gsantner
Copy link
Owner

Thank you, I will try to find time on sunday to review

@gsantner gsantner merged commit a029a82 into gsantner:master Dec 27, 2025
1 check passed
@pgorod
Copy link

pgorod commented Jan 5, 2026

Hi. Should this affect delays that I am experiencing such as

  • opening a file
  • opening/closing the keyboard
  • navigating to a chapter

Or will it affect only opening the app itself?

I ask because I was about to open an Issue about a very noticeable performance degradation when upgrading from 2.14.1 to 2.15.2 (which still does not include this PR).

My problem is with a very large markdown file (214Kb, 3717 lines, hundreds of headings). But I've always used this big file quite successfully with Markor...

Should I open the Issue or is it better to wait for this PR to come out in a release?

Thanks! I love Markor!

@harshad1
Copy link
Collaborator Author

harshad1 commented Jan 5, 2026

There should not have been a regression between 2.14.1 and 2.15.2.

Could you share a file and steps to reproduce? Perhaps in a ticket.

@harshad1
Copy link
Collaborator Author

harshad1 commented Jan 5, 2026

This PR should only affect startup times (indirectly perceived load time)

@guanglinn
Copy link
Contributor

Hi, @harshad1

The master branch code after merging this PR will throw NullPointerException here:

2026-01-06-NullPointerException.png

Steps to reproduce:

  1. Open a Markdown file;
  2. Switch to view-mode;
  3. Long press the action bar.

@pgorod
Copy link

pgorod commented Jan 6, 2026

Could you share a file and steps to reproduce? Perhaps in a ticket.

Done, #2716

Thanks!

@gsantner
Copy link
Owner

gsantner commented Jan 8, 2026

I couldn't reproduce the webview crash, but I pushed a change to master to add a check there, which should fix that for you.

@gsantner gsantner added this to the Markor v2.16 milestone Jan 8, 2026
@gsantner gsantner linked an issue Jan 8, 2026 that may be closed by this pull request
4 tasks
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.

Performance degradation from 2.14.1 to 2.15.2

4 participants