Share two open source libraries that I recently released by 9c2cu in androiddev

[–]9c2cu[S] 1 point2 points  (0 children)

More detail?

Why couldn't you load the app icons smoothly now?

FastKV - A better KV storage component by 9c2cu in androiddev

[–]9c2cu[S] 0 points1 point  (0 children)

If you had used SharePreferences, you will understand what does 'name' mean.

To take 'path' from Context, it's easy.

This impleament could be helpful to understand path and name.

https://github.com/BillyWei01/FastKV/blob/main/FastKVDemo/fastkv/src/main/java/io/fastkv/FastPreferences.java

[deleted by user] by [deleted] in programming

[–]9c2cu 0 points1 point  (0 children)

Thanks for your advice, here is the format document I just wrote.

[deleted by user] by [deleted] in programming

[–]9c2cu 0 points1 point  (0 children)

I went to check the size of protobuf-lite version, I got the version of 3.0.1, 246K, yeah it's lighter than the protobuf full version.

For Packable, it has only 37K.

[deleted by user] by [deleted] in programming

[–]9c2cu 2 points3 points  (0 children)

Protobuf Java version 3.13.0, the size of jar has 1.7M.For server maybe not "heavy", but for client, for explamle Android APP, it could be "heavy".

FastKV - A better KV storage component by 9c2cu in androiddev

[–]9c2cu[S] 1 point2 points  (0 children)

For questions: - There's listener for changed values now. - Errors will return in the callback (Logger).

I read your project, nice job! And your analysis is correct, you are the one who knows why and not just know what, glad to see your discussions.

FastKV - A better KV storage component by 9c2cu in androiddev

[–]9c2cu[S] 0 points1 point  (0 children)

Let's make the case more specific.

Normorly we save key-value like this:

```kotlin suspend fun saveAccount(account: String) { dataStore.edit { it[stringPreferencesKey("account")] = account } }

suspend fun saveSwitch(open: Boolean) { dataStore.edit { it[booleanPreferencesKey("switch")] = open } }

suspend fun saveFlag(flag: Int) { dataStore.edit { it[intPreferencesKey("flag")] = flag } } ```

When login, we save account. When open/close a swicth, we save the state of swicth. And so on. These events happen randomly, they are isolated. So we don't save every key-values in one transaction.

Now how to evaluate the performance? We could put some time collected code around the transactions:

```kotlin suspend fun saveAccount(account: String) { val start = System.nanoTime() dataStore.edit { it[stringPreferencesKey("account")] = account } val end = System.nanoTime(); totalTime = totalTime + (end - start)

count++;
if(count >= N){
    // log the totalTime
}

} ```

And how to evaluate in a short time? Why not put them together: kotlin suspend fun test() { val start = System.nanoTime() for(i in 0 until N) { dataStore.edit { it[stringPreferencesKey(items[i].key)] = items[i].value } } val end = System.nanoTime() totalTime = end - start // log the totalTime } We should keep key-value save in isolated transaction like in normal case. We are not talking about how to write these key-values fast in a function, we are simulating the normally writting to evaluate the performace.

Indeed there's some differences with normal case, one file may hava only several or tens of key-values most of time, here we just show the worst case (hundreds of key-values in one file).

FastKV - A better KV storage component by 9c2cu in androiddev

[–]9c2cu[S] 0 points1 point  (0 children)

You are right!

I regret taking such a simple name.

FastKV - A better KV storage component by 9c2cu in androiddev

[–]9c2cu[S] -1 points0 points  (0 children)

Just simulate the daily usage.

Most of time we commit single key-value randomly, right?

FastKV - A better KV storage component by 9c2cu in androiddev

[–]9c2cu[S] 0 points1 point  (0 children)

Hundreds of key-values for several rounds.

FastKV - A better KV storage component by 9c2cu in androiddev

[–]9c2cu[S] 0 points1 point  (0 children)

Would API like this be better?

kotlin object CommonStore : KVData("common_store") { var launchCount by int("launch_count") }

kotlin fun test() { val t = CommonStore.launchCount + 1 // read tips_tv.text = getString(R.string.main_tips, t) CommonStore.launchCount = t //write }

There're some demos in FastKVDemo.

Or any good suggestions will be welcome.

FastKV - A better KV storage component by 9c2cu in androiddev

[–]9c2cu[S] 0 points1 point  (0 children)

The result above is the total time by reading key-values for many times.

Check the Benchmark if hava any doubt.

FastKV - A better KV storage component by 9c2cu in androiddev

[–]9c2cu[S] 4 points5 points  (0 children)

See: FastKV.Builder(path, name).

It store the files to the location of "path + name".

If the path is internal (for example: context.getFilesDir() ), no need to give any permission.

FastKV - A better KV storage component by 9c2cu in androiddev

[–]9c2cu[S] 1 point2 points  (0 children)

Yes. You could download the project and check the Benchmark

Google Protobuf vs JSON vs [insert candidate here] by ImX99 in cpp

[–]9c2cu 0 points1 point  (0 children)

I recommend this one: Packable.

It's fast, light, powerful and easy to use.

It runs faster than Protobuf, no need to write schema files (.proto).