Closed Bug 656188 Opened 14 years ago Closed 14 years ago

Cache last 10 fetched bookmarks info to speed up repeated requests

Categories

(Toolkit :: Places, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla6

People

(Reporter: mak, Assigned: mak)

References

Details

(Keywords: perf, Whiteboard: [fixed-in-places])

Attachments

(1 file, 2 obsolete files)

this can help Sync, transactions manager and bookmarks dialogs till we put together a new API, since most of the getters after bug 633274 go through a single getter method, it can easily manage a cache of recent fetches.
Keywords: perf
OS: Windows 7 → All
Hardware: x86 → All
Attached patch patch v1.0 (obsolete) — Splinter Review
Was easier than I thought, not asking review yet, till the dependency is fixed. 2 downsides to this: - Changes to bookmarks service need a bit more attention. Mostly any method changing something has to invalidate the cache (this comes almost for free now, but future changes must take this into account) - Direct writes to the database may confuse the cache. But we don't expect anyone to directly UPDATE or DELETE from moz_bookmarks.
Assignee: nobody → mak77
Status: NEW → ASSIGNED
Attached patch patch v1.1 (obsolete) — Splinter Review
no hurry on this. I think I can't write a better test for this than the >150 tests we already have.
Attachment #531759 - Attachment is obsolete: true
Attachment #532347 - Flags: review?(sdwilsh)
PS: I had to change the test because it's doing a direct write on the db, clearly the cache becomes confused.
As an idea for a future notification API, we could notify just things like onItemRemoved(guid), onItemAdded(guid) and store a timed cache (like 5 minutes) of the item, the listener could use any getter api (getTitle, getURI) in the notification based on his needs, hitting our internal cache.
Comment on attachment 532347 [details] [diff] [review] patch v1.1 Review of attachment 532347 [details] [diff] [review]: ----------------------------------------------------------------- r=sdwilsh ::: toolkit/components/places/nsNavBookmarks.cpp @@ +208,5 @@ > +{ > + if (hashTable->Count() > RECENT_BOOKMARKS_INITIAL_CACHE_SIZE) { > + PRInt64 threshold = PR_Now() - RECENT_BOOKMARKS_THRESHOLD; > + hashTable->Enumerate(ExpireNonrecentBookmarksCallback, > + reinterpret_cast<void*>(&threshold)); Doesn't Enumberate return something? Either check it or cast to void please. ::: toolkit/components/places/nsNavBookmarks.h @@ +209,3 @@ > */ > nsresult FetchItemInfo(PRInt64 aItemId, > + mozilla::places::BookmarkData& _bookmark, I thought we did typedef mozilla::places::BookmarkData BookmarkData; so we didn't need to include this here. @@ +573,5 @@ > + /** > + * Cache for the last fetched BookmarkData entries. > + * This is used to speed up repeated requests to the same item id. > + */ > + nsDataHashtable<nsTrimInt64HashKey, mozilla::places::BookmarkData> mBookmarksInfoCache; I'd really prefer us to use nsTHashTable here.
Attachment #532347 - Flags: review?(sdwilsh) → review+
Attached patch patch v1.2Splinter Review
Addressed all comments
Attachment #532347 - Attachment is obsolete: true
Whiteboard: [fixed-in-places]
http://hg.mozilla.org/mozilla-central/rev/504270705d88 marking in-testsuite since this code is leveraged by most of the existing tests.
Status: ASSIGNED → RESOLVED
Closed: 14 years ago
Flags: in-testsuite+
Resolution: --- → FIXED
Target Milestone: --- → mozilla6
Will this be used when using the awesomebar? Say, typing * to get recent bookmarks, or + foo to get bookmarks with the tag "foo"? If so, would it make sense to increase the number of cached items from 10 to 12 as that is the number of items that appears in the dropdown? Sorry if I've completely misunderstood this cache.
no, the awesomebar follows another path. This will be useful for Sync and for bookmarks organization (remove, move, drag&drop, copy&paste and such).
and for add-ons using the bookmarks API
Depends on: 675416
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: