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

Optimisation of history entry saving #675

Merged
merged 5 commits into from
Aug 9, 2022

Conversation

tomasstrba
Copy link
Contributor

Task/Issue URL: https://app.asana.com/0/1177771139624306/1202660511799171/f

Description:
This PR refactors saving of history URLs. The original implementation saves data to the Core Data store on every change and makes too many requests on sites with trackers.

After this change, Core Data Saves on cnn.com are reduced from almost 100 calls to 5. Those remaining 5 aren't related to history.

Steps to test this PR:

  1. Visit any site. More trackers it contains the better.
  2. Make sure it is included in homepage feed and history menu.
  3. Restart the app and make sure the information is persisted
  4. Use Core Data from Instruments and take a look at Core Data Saves when navigating to new websites

Testing checklist:

  • Test proper deallocation of tabs

Internal references:

Software Engineering Expectations
Technical Design Template
When ready for review, remember to post the PR in MM

}
}

func markFailedToLoadUrl(_ url: URL) {
mark(url: url, keyPath: \HistoryEntry.failedToLoad, value: true)
}

func commitChanges(url: URL) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The point of the optimisation to commit (save) once when we no longer expect changes related to the url. It means, user navigated to other url or closed the tab

@samsymons samsymons self-assigned this Aug 8, 2022
@@ -318,14 +327,20 @@ final class HistoryCoordinator: HistoryCoordinating {
}

private func makeHistoryDictionary(from history: History) -> [URL: HistoryEntry] {
history.reduce(into: [URL: HistoryEntry](), { $0[$1.url] = $1 })
dispatchPrecondition(condition: .onQueue(queue))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Happy to see more dispatchPrecondition 👍

Copy link
Collaborator

@samsymons samsymons left a comment

Choose a reason for hiding this comment

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

Nice, Instruments is much quieter now, this is a solid change. 👍

@samsymons samsymons assigned tomasstrba and unassigned samsymons Aug 8, 2022
@tomasstrba
Copy link
Contributor Author

Thank you Sam! :)

@tomasstrba tomasstrba merged commit 6a32c1a into develop Aug 9, 2022
@tomasstrba tomasstrba deleted the tom/save-entry-optimisation branch August 9, 2022 10:21
samsymons added a commit that referenced this pull request Aug 15, 2022
* develop:
  Bookmarks phase 2 bug fixes (#686)
  Attempt to stop the new tab button from jumping around the UI (#685)
  Fix of threading issues related to history causing crashes  (#688)
  Add empty autofill isEnabled checks (to update BSK) (#683)
  Bump BSK to a version that uses updated GRDB (#647)
  Fix Save Credentials popover on macOS Ventura (#672)
  Update BSK to latest version + noop updates (#669)
  Update selectedTabViewModel only when it actually changes (#681)
  Update BSK to version 21.0.0 (#680)
  Always add the Autoconsent script (#666)
  Optimisation of history entry saving (#675)
samsymons added a commit that referenced this pull request Aug 18, 2022
# By Sam Symons (14) and others
# Via GitHub (1) and others
* develop: (45 commits)
  Revert "Prevent the app from quitting while the Fire button is active" (#690)
  Disable link preview. (#691)
  Fire Button quick wins (#677)
  Bookmarks phase 2 bug fixes (#686)
  Set version to 0.28.3.
  Only clear the selection if the selection needs to change. (#689)
  Set version to 0.28.2.
  Update embedded files for 0.28.2.
  Attempt to stop the new tab button from jumping around the UI (#685)
  Fix of threading issues related to history causing crashes  (#688)
  Add empty autofill isEnabled checks (to update BSK) (#683)
  Bump BSK to a version that uses updated GRDB (#647)
  Fix Save Credentials popover on macOS Ventura (#672)
  Update BSK to latest version + noop updates (#669)
  Update selectedTabViewModel only when it actually changes (#681)
  Update BSK to version 21.0.0 (#680)
  Always add the Autoconsent script (#666)
  Optimisation of history entry saving (#675)
  Use localized compare to sort autofill items (#674)
  0.28.1
  ...

# Conflicts:
#	DuckDuckGo.xcodeproj/project.pbxproj
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.

2 participants