在使用Map这种数据类型时需要注意的几个问题

file

  • 因为性能的原因map一般实现不支持写的并发,如果是并发场景需要确认map的实现是否支持或者更换为支持的实现。
  • map的值类型一般不需要关心,但是键很重要,涉及到hash的原理和实现的算法,所以键的特殊类型会影响性能。
  • 触发扩容,一般实现中扩容并不会影响性能,大部分算法都是在插入和删除时进行,但是有的算法会主动进行迁移,比如redis,内存也会产生波动,对于生产环境特别需要注意。
  • 各种实现之间的差异除了架构上,算法也会有,主要体现在冲突key的解决方法上,但是各种方法各有利弊,所以能分成多个map就不要塞到一起去。
作者

Carry

发布于

2022-01-19

更新于

2026-05-23

许可协议

You need to set install_url to use ShareThis. Please set it in _config.yml.
You forgot to set the business or currency_code for Paypal. Please set it in _config.yml.

评论

You forgot to set the shortname for Disqus. Please set it in _config.yml.
You need to set client_id and slot_id to show this AD unit. Please set it in _config.yml.