Map.set
is really slow for me. Taking 14.677 seconds to set 300-400 items. I’m using Chrome for testing.
I’ve created a custom Map object:
export class DataMap<T> extends Map<string, T> {
constructor(...args:MapConstructorParameters){
super(...(args as []))
}
updateFromList(values:any[], {key='id', sortKey=null} : UpdateFromListOptions){
// const self = this;
let _values:any[];
if (sortKey){
console.log('Sorting')
_values = this._sortValues(values, sortKey) // implementation not shown for brevity
console.log('Sorting Finished')
} else {
_values = []
}
console.log('Setting')
_values.forEach((_:any)=>{
this.set(_[key], _ as T)
})
console.log('Setting finished')
}
}
The idea of updateFromList
is a little bit of syntax sugar, to allow passing of a list of objects and append them by a ‘key’ to the map. The part that is really slow is this:
console.log('Setting')
_values.forEach((_:any)=>{
this.set(_[key], _ as T)
})
console.log('Setting finished')
Is this use of the Map
a no go or am doing something stupid here?