问题描述
我有这样的数据结构
{
"stores": [
{ code: 'A7-22',name: 'market'},{ code: 'A8-22',name: 'drugstore'},... 250 items
]
}
const code = 'A7-22';
const store = data.stores.find(store => store.code === code)
但是我认为将数据结构更改为
{
"stores": {
'A7-22': {name: 'market'},'A8-22': { name: 'drugstore'},... 250 items
]
}
现在代码更易于处理:
const code = 'A7-22';
const store = data.stores[code]
现在,考虑到此代码正在高流量的后端工件中运行,并且将来的商店可能会超过10.000。
问题是: 如果我使用带有“键值策略”的大对象来选择2,则与该代码相关的一些性能问题?
解决方法
是的,绝对第二种选择更快。这是两种情况的挑战:
getConversationMembers
请注意,您提到的高流量在这里并不重要,因为此代码在客户端中运行。