nextcloud / nextcloud/notes-android

When syncing large note: `OutOfMemoryError` via `generateNoteExcerpt` in `NoteUtil`

Open
#1,901 0 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug Performance 🚀
Dominant language
Java
Stars
1.1k
Forks
168
Avg merge
1d 17h
Merged PRs (30d)
31

Description

Please use GitHub reactions 👍 to show that you are affected by the same issue. Please don't comment if you have no relevant information to add!

Describe the bug

To Reproduce
Steps to reproduce the behavior:

  1. Have a large TXT file somewhere in your cloud
  2. In the nextcloud notes app, change the notes folder from "Notes" to root
  3. Open the android app
  4. Wait on main screen (notes list) for completion of sync
  5. See error

Unfortunately the error persists after several restarts of the app. The only way to solve it was to identify and rename the large TXT file blocking the sync.

Expected behavior

Sync all notes without errors. If syncing all at once is too memory intensive, sync in batches (and clean up memory in between).

Also I would not expect the app to parse the full markdown just to create a preview excerpt with the first 200 char. Instead, parsing the first few non-empty lines or 1000 chars only could save a lot of memory. If really required, more lines/chars can be parsed iteratively.
And for a TXT file, there is no point in parsing markdown at all.

Screenshots

Smartphone (please complete the following information):

  • Nextcloud Notes-Version (android app): 4.1.0 (40010090)
  • F-Droid or Play Store: play
  • Android-Version: 13 (API 33)
  • Device: SM-G781B

Server

  • Nextcloud version: 26.0.5
  • Nextcloud Notes version (server app): 4.8.1

Stacktrace

java.lang.OutOfMemoryError: Failed to allocate a 32 byte allocation with 125776 free bytes and 122KB until OOM, target footprint 268435456, growth limit 268435456; giving up on allocation because <1% of heap free after GC.
	at org.commonmark.internal.InlineParserImpl.parseNewline(InlineParserImpl.java:301)
	at org.commonmark.internal.InlineParserImpl.parseInline(InlineParserImpl.java:196)
	at org.commonmark.internal.InlineParserImpl.parse(InlineParserImpl.java:153)
	at org.commonmark.internal.ParagraphParser.parseInlines(ParagraphParser.java:53)
	at org.commonmark.internal.DocumentParser.processInlines(DocumentParser.java:422)
	at org.commonmark.internal.DocumentParser.finalizeAndProcess(DocumentParser.java:480)
	at org.commonmark.internal.DocumentParser.parse(DocumentParser.java:117)
	at org.commonmark.parser.Parser.parse(Parser.java:69)
	at it.niedermann.android.markdown.MarkdownUtil.removeMarkdown(MarkdownUtil.java:521)
	at it.niedermann.owncloud.notes.shared.util.NoteUtil.generateNoteExcerpt(NoteUtil.java:67)
	at it.niedermann.owncloud.notes.persistence.NotesRepository.addNote(NotesRepository.java:441)
	at it.niedermann.owncloud.notes.persistence.NotesServerSyncTask.pullRemoteChanges(NotesServerSyncTask.java:239)
	at it.niedermann.owncloud.notes.persistence.NotesServerSyncTask.run(NotesServerSyncTask.java:96)
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:463)
	at java.util.concurrent.FutureTask.run(FutureTask.java:264)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1137)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:637)
	at java.lang.Thread.run(Thread.java:1012)

Sometimes also:

java.lang.OutOfMemoryError: OutOfMemoryError thrown while trying to throw an exception; no stack trace available

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at NoteUtil.generateNoteExcerpt in NoteUtil.java:67 and follow its call from NotesRepository.addNote during NotesServerSyncTask.pullRemoteChanges. Reproduce the failure with a large TXT file and verify that sync completes without an OutOfMemoryError while generating the 200-character excerpt.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, java
Domain
mobile-dev, performance
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.