2017년 3월 17일 금요일

How Hard Can You Push TinyDb?


I am sure these questions have been addressed somewhere by someone, but I'd like to get definitive answers from the gurus of this forum:
1. What is the maximum number of tag TinyDb can store?
2. When this maximum number of tag is exceeded, will TinyDb return an error message (like "max number of tags exceeded") an error code (like "error number 1234567890") or the program just bomb out?

3. What is the maximum size (length, number of characters) of each tag's content?


--
I am sure these questions have been addressed somewhere by someone, but I'd like to get definitive answers from the gurus of this forum:
1. What is the maximum number of tag TinyDb can store?
Under the hood, TinyDB is implemented in terms of android.content.SharedPreferences. According to this Stack Overflow post, share preferences are represented as an XML file stored in /data/data/[package name]/shared_prefs/[app name].xml. So the only space limitations involved are whether the device can store this file. There is no inherent limit on the number of tags. 
2. When this maximum number of tag is exceeded, will TinyDb return an error message (like "max number of tags exceeded") an error code (like "error number 1234567890") or the program just bomb out?
The source code uses an android.content.SharedPreferences.Editor to store key/value pairs, and uses its commit operation to commit the transaction. It's not clear from the documentation what happens if there's not enough space for the resulting XML file. I would assume the commit returns false in this case, but I'm not sure. However, there's no check for the false case in the App Inventor code, so my best guess is that this would fail silently. We'll look into this case. 
3. What is the maximum size (length, number of characters) of each tag's content?
The content of each tag (which can be an arbitrary value) is converted to JSON and is stored as a string. As in the answer to question #1, there is no inherent limitation on the size of this string.  

--
with regards to question 3, there are some limitations that you can see here:

http://developer.android.com/reference/java/util/prefs/Preferences.html#MAX_KEY_LENGTH
http://developer.android.com/reference/java/util/prefs/Preferences.html#MAX_VALUE_LENGTH

So key length is 80 chars, and value length is 8192 chars. 

--
The comments in this Stack Overflow post point out that the limitations on the Preference class don't apply to the SharedPreferences class. 

Indeed, I just wrote two simple App Inventor 2 apps to verify this (attached). The TinyDBKeyLimit app starts with a key that's one character long and keeps doubling it until the application crashes. The TindyDBValueLimit app is similar, but keeps doubling the stored value string until the app crashes. In both cases, the app does not crash until after a key/value length of 8,388,608 characters is reported.  So the Preference limitations are clearly irrelevant for SharedPreferences and TinyDB.



--

댓글 없음:

댓글 쓰기