1、不要使你的文件过大
Sp 在创建的时候会吧整个xml问文件全部载入内存,如果你的文件比较大:
1、第一次从sp取值时,会阻塞主线程,使页面卡顿。
2、解析sp的时候会产生大量的临时对象,导致频繁GC
3、key value 会永远在内存中,占大量内存。
2、不要把无关的配置绑在一个文件里:
3、频繁读取的key和不易变动的key不要放在一起
4、不要在sp里放很大的JSON或HTML
JSON或HTML格式存放在sp里面的时候,需要转义,这样会带来很多&
这种特殊符号,sp在解析碰到这个特殊符号的时候会进行特殊的处理,引发额外的字符串拼接以及函数调用开销。
5、避免多次edit多次apply
apply 会把操作提交给一个单线程的队列.