-
Notifications
You must be signed in to change notification settings - Fork 470
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
数据库表中json字段使用的TEXT类型存储,是否尝试过存BLOB类型的NSData #24
Comments
苹果的 NSJSONSerialization 确实效率很低下。这是一个问题。。。 2016-06-27 16:36 GMT+08:00 Witty Young notifications@github.com:
|
@tangqiaoboy 结论是啥?不改成NSKeyedArchiver的原因是不是兼容已有的代码?如果我要对数据进行版本迁移,目前还不支持。例如数据从未加密加密,甚至是包括存储从NSJSONSerialization改成NSKeyedArchiver。只能简单粗暴地删除所有的缓存key value内容? |
对,主要考虑的是兼容性问题,我不能简单就改数据结构,不然那些用了这个库的同学会被坑的,他们可能会发现简单升了一下级,以前的数据都无法读取了。但是要支持升级功能会比较麻烦,即使是号称升级方便的 realm,也需要程序员做额外的工作。 如果你没有兼容性的顾虑的话,我个人建议你直接 fork 一个分支把这个改掉。 |
使用过程中,发现单张table的大小有些夸张:
1、存储1万条数据,使用NSJSONSerialization转TEXT类型存储后的大小是4.4M;
2、改变表里存的json string数据类型为data后,改用NSKeyedArchiver将jsonObject转NSData,大小为61k;
请问是否有做过此类的测试?
测试代码如下:
YTKKeyValueStore *store = [[YTKKeyValueStore alloc] initDBWithName:@"test.db"];
NSString *tableName = @"zm_table";
[store createTableWithName:tableName];
测试形式:
NSData * data = [NSJSONSerialization dataWithJSONObject:object options:0 error:&error];
NSData *data1 = [NSKeyedArchiver archivedDataWithRootObject:object];
测试结果:
2016-03-23 10:40:14.154 YTKKeyValueStore[68148:2019750] JSONSerialization Data Size = 4.4 MB
2016-03-23 10:40:14.154 YTKKeyValueStore[68148:2019750] KeyedArchiver Data Size = 61 KB
谢谢!
The text was updated successfully, but these errors were encountered: