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

perf: don't create thumbnails when auto-saving #1175

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

QubaB
Copy link
Contributor

@QubaB QubaB commented Mar 15, 2024

When note is autosaved, there is no need to create a thumbnail which causes small lag during hang writing.

New SavingState.savedNeedThumbnailUpdate state is implemented indicating that note is saved but thumbnail is not created.

On editor exit is checked this state and thumbnail is created.

PreviewCard fileWriteListener is listening to write to thumbnail file to be able to detect change of thumbnail itself.

Closes #1164 (or at least lag is smaller)

Jakub Zlámal added 3 commits March 15, 2024 14:53
…mall lag. At the end of noete editting is tested state and if thumbnail is not created it is called.
…mbnail) file not note file itself. Because Autosave now saves only note itself, but does not create thumbnail. Thumbnail can be created on editor exit but note itself is not updated.

This cause update of thumbnail at any case.
Copy link

codecov bot commented Mar 15, 2024

Codecov Report

Attention: Patch coverage is 32.55814% with 29 lines in your changes are missing coverage. Please review.

Project coverage is 36.96%. Comparing base (a74d961) to head (fb38bf1).
Report is 7 commits behind head on main.

Files Patch % Lines
lib/pages/editor/editor.dart 36.36% 21 Missing ⚠️
lib/components/canvas/save_indicator.dart 33.33% 4 Missing ⚠️
lib/components/navbar/responsive_navbar.dart 0.00% 2 Missing ⚠️
lib/components/home/preview_card.dart 0.00% 1 Missing ⚠️
lib/pages/home/whiteboard.dart 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1175      +/-   ##
==========================================
- Coverage   37.50%   36.96%   -0.54%     
==========================================
  Files         108      108              
  Lines        8554     8576      +22     
==========================================
- Hits         3208     3170      -38     
- Misses       5346     5406      +60     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@adil192 adil192 changed the title feat: Autosave only saves note. Does not create thumbnail perf: don't create thumbnails when auto-saving Mar 18, 2024
@adil192
Copy link
Member

adil192 commented Mar 18, 2024

Drawing something and clicking save gives me this error:

Launching lib/main.dart on Linux in debug mode...
Building Linux application...                                           
Syncing files to device Linux...                                   205ms

Flutter run key commands.
r Hot reload. 🔥🔥🔥
R Hot restart.
h List all available interactive commands.
d Detach (terminate "flutter run" but leave application running).
c Clear the screen
q Quit (terminate the application on the device).

A Dart VM Service on Linux is available at: http://127.0.0.1:41135/rKfNL5wM7bs=/
The Flutter DevTools debugger and profiler on Linux is available at:
http://127.0.0.1:9101?uri=http://127.0.0.1:41135/rKfNL5wM7bs=/
flutter: dynamic_color: Accent color detected.
flutter: INFO: FileSyncer: Adding /24-03-18 Untitled.sbn2 to upload queue

══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY
╞═══════════════════════════════════════════════════════════
The following assertion was thrown building Directionality(textDirection: ltr):
'package:flutter/src/widgets/framework.dart': Failed assertion: line 2115 pos 12:
'_elements.contains(element)': is not true.

Either the assertion indicates an error in the framework itself, or we should
provide substantially
more information in this error message to help you determine and fix the underlying
cause.
In either case, please report this assertion by filing a bug on GitHub:
  https://github.com/flutter/flutter/issues/new?template=2_bug.yml

The relevant error-causing widget was:
  Directionality
  Directionality:file:///home/ahann/.pub-cache/hosted/pub.dev/screenshot-2.1.0/lib/
  screenshot.dart:189:20

When the exception was thrown, this was the stack:
#2      _InactiveElements.remove
(package:flutter/src/widgets/framework.dart:2115:12)
#3      Element._retakeInactiveElement
(package:flutter/src/widgets/framework.dart:4266:30)
...     Normal element mounting (7 frames)
#10     Element.inflateWidget (package:flutter/src/widgets/framework.dart:4335:16)
#11     Element.updateChild (package:flutter/src/widgets/framework.dart:3846:18)
#12     RenderObjectToWidgetElement._rebuild
(package:flutter/src/widgets/adapter.dart:143:16)
#13     RenderObjectToWidgetElement.mount
(package:flutter/src/widgets/adapter.dart:112:5)
#14     RenderObjectToWidgetAdapter.attachToRenderTree.<anonymous closure>
(package:flutter/src/widgets/adapter.dart:61:18)
#15     BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2844:19)
#16     RenderObjectToWidgetAdapter.attachToRenderTree
(package:flutter/src/widgets/adapter.dart:60:13)
#17     ScreenshotController.widgetToUiImage
(package:screenshot/screenshot.dart:192:16)
#18     ScreenshotController.captureFromWidget
(package:screenshot/screenshot.dart:106:28)
#19     EditorState.createThumbnailPreview
(package:saber/pages/editor/editor.dart:890:43)
#20     EditorState.saveToFile (package:saber/pages/editor/editor.dart:875:32)
<asynchronous suspension>
(elided 2 frames from class _AssertionError)

═══════════════════════════════════════════════════════════════════════════════════
═════════════════

[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: Looking up a deactivated widget's ancestor is unsafe.
At this point the state of the widget's element tree is no longer stable.
To safely refer to a widget's ancestor in its dispose() method, save a reference to the ancestor by calling dependOnInheritedWidgetOfExactType() in the widget's didChangeDependencies() method.
#0      Element._debugCheckStateIsActiveForAncestorLookup.<anonymous closure> (package:flutter/src/widgets/framework.dart:4738:9)
#1      Element._debugCheckStateIsActiveForAncestorLookup (package:flutter/src/widgets/framework.dart:4752:6)
#2      Element.dependOnInheritedWidgetOfExactType (package:flutter/src/widgets/framework.dart:4771:12)
#3      ModalRoute.of (package:flutter/src/widgets/routes.dart:1046:47)
#4      GoRouterState.of (package:go_router/src/state.dart:119:51)
#5      _RecentPageState.findRecentlyAccessedNotes (package:saber/pages/home/recent_notes.dart:90:38)
#6      _RecentPageState.fileWriteListener (package:saber/pages/home/recent_notes.dart:80:5)
#7      _RootZone.runUnaryGuarded (dart:async/zone.dart:1594:10)
#8      _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:339:11)
#9      _DelayedData.perform (dart:async/stream_impl.dart:515:14)
#10     _PendingEvents.handleNext (dart:async/stream_impl.dart:620:11)
#11     _PendingEvents.schedule.<anonymous closure> (dart:async/stream_impl.dart:591:7)
#12     _microtaskLoop (dart:async/schedule_microtask.dart:40:21)
#13     _startMicrotaskLoop (dart:async/schedule_microtask.dart:49:5)

[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: Looking up a deactivated widget's ancestor is unsafe.
At this point the state of the widget's element tree is no longer stable.
To safely refer to a widget's ancestor in its dispose() method, save a reference to the ancestor by calling dependOnInheritedWidgetOfExactType() in the widget's didChangeDependencies() method.
#0      Element._debugCheckStateIsActiveForAncestorLookup.<anonymous closure> (package:flutter/src/widgets/framework.dart:4738:9)
#1      Element._debugCheckStateIsActiveForAncestorLookup (package:flutter/src/widgets/framework.dart:4752:6)
#2      Element.dependOnInheritedWidgetOfExactType (package:flutter/src/widgets/framework.dart:4771:12)
#3      ModalRoute.of (package:flutter/src/widgets/routes.dart:1046:47)
#4      GoRouterState.of (package:go_router/src/state.dart:119:51)
#5      _RecentPageState.findRecentlyAccessedNotes (package:saber/pages/home/recent_notes.dart:90:38)
#6      _RecentPageState.fileWriteListener (package:saber/pages/home/recent_notes.dart:80:5)
#7      _RootZone.runUnaryGuarded (dart:async/zone.dart:1594:10)
#8      _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:339:11)
#9      _DelayedData.perform (dart:async/stream_impl.dart:515:14)
#10     _PendingEvents.handleNext (dart:async/stream_impl.dart:620:11)
#11     _PendingEvents.schedule.<anonymous closure> (dart:async/stream_impl.dart:591:7)
#12     _microtaskLoop (dart:async/schedule_microtask.dart:40:21)
#13     _startMicrotaskLoop (dart:async/schedule_microtask.dart:49:5)

Another exception was thrown: Duplicate GlobalKey detected in widget tree.
flutter: INFO: FileSyncer: Adding /24-03-18 Untitled.sbn2.p to upload queue
flutter: dynamic_color: Accent color detected.

Performing hot reload...                                                
Reloaded 1 of 3368 libraries in 4,884ms (compile: 53 ms, reload: 4478 ms,
reassemble: 194 ms).
Lost connection to device.

@QubaB
Copy link
Contributor Author

QubaB commented Mar 19, 2024

I will try to look at this problem.

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

Successfully merging this pull request may close these issues.

Lags, probably during autosave
2 participants