There are times when I want to get all the objects that are stored in Ionic Storage for a subset of keys.
I have implemented a wrapper around Storage that mirrors the functionality so that I can substitute it out as @rapropos suggested in this post.
Right now I am testing my application on an iPhone 7+ and with a data set of 435 entries it is taking 6+ seconds to iterate through the keys, filter the keys based on some prefix, and then get the objects associated with those keys.
Perhaps i am doing something wrong in this code that will be obvious to you guys but I am not sure what it is.
I am considering switching to SQLLite but would rather stick with Ionic Storage if possible.
Here is the offending function:
constructor(private storage: Storage) {
console.log(Storage Provider: created with driver = ${storage.driver}
)
}
public getAll(keyPrefix:string) : Observable<any> {
let keysObs : Observable<string[]> =
Observable.fromPromise( <Promise<string[]>>this.storage.keys());
let flatKeys : Observable<string> = keysObs.mergeMap( (keys:string[]) => {
return Observable.from(keys);
});
let filteredKeys: Observable<string> = flatKeys.filter( (key:string) => {
let prefixIndex:number = key.indexOf(keyPrefix);
return prefixIndex == 0
}
);
let itemPromises: Observable<Observable<any>> = filteredKeys.map(
(key:string) => {
//console.debug("Retrieving from storage with key = ", key);
return Observable.fromPromise(this.storage.get(key)) }
);
return itemPromises.mergeAll();
}
At a higher level I am not even sure how to profile my code to see which 20% of the code is taking up 80% of the time. It might not even be happening in this block. If this were a C# or Java project then I would just fire up the profiler, run the application a couple of times and see where the hot spots are. What do people out there do to profile their code?
I looked into using XCode instruments but am skeptical that it will give me meaningful function level reporting given that my XCode project shows just the output from the ionic build and not the source Typescript and Javascript that is used to generate the XCode project.
Any thoughts/suggestions would be most helpful.
-Harley