Comments (12)
Or maybe it's possible to load a compressed file from the start?
from threetenabp.
It is always required as it loads the timezone database.
from threetenabp.
And it's already compressed
from threetenabp.
Why do I need the timezone, though?
I mean, the LocalDate doesn't have a timezone...
And, is it possible to use the built in one of Android API 26, instead of the one of the library, when it's the current one that the app runs on ?
This could remove the need of this initialization...
from threetenabp.
from threetenabp.
That's too bad.
About compression, I think it can be better compressed, even with zip.
Look :
from threetenabp.
from threetenabp.
But isn't loading from storage the slower part?
I mean, RAM&CPU usage is always faster than disk read, no?
Or maybe it depends on the file that's loaded?
I guess if the compression is too complex, it could in theory become slower, but is it really the case here?
from threetenabp.
from threetenabp.
I've tested the next codes, and compared the time it took for both:
private fun originalLoading() {
val provider: TzdbZoneRulesProvider
var inputStream: InputStream? = null
try {
inputStream = resources.openRawResource(R.raw.original)
provider = TzdbZoneRulesProvider(inputStream)
} catch (e: IOException) {
throw IllegalStateException("TZDB.dat missing from assets.", e)
} finally {
if (inputStream != null) {
try {
inputStream.close()
} catch (ignored: IOException) {
}
}
}
ZoneRulesProvider.registerProvider(provider)
}
private fun newLoading() {
val provider: TzdbZoneRulesProvider
var zin: InputStream? = null
try {
zin = ZipInputStream(resources.openRawResource(R.raw.tzdb))
val ze = zin.nextEntry
provider = TzdbZoneRulesProvider(zin)
zin.closeEntry();
} catch (e: IOException) {
throw IllegalStateException("TZDB.dat missing from assets.", e)
} finally {
if (zin != null) {
try {
zin.close()
} catch (ignored: IOException) {
}
}
}
ZoneRulesProvider.registerProvider(provider)
}
I'm not sure if I did the correct unzip-loading, but newLoading
took around 90 ms, while the originalLoading
took around 60 ms.
So I think you are right here.
Did I implement it correctly though?
And why did you put the file in the assets folder? Just to keep its original file name?
I think using assets folder is almost the same as the raw resource folder, no?
from threetenabp.
from threetenabp.
An explanation to what? The assets decision? This :
For some reason getResourceAsStream() does some rather extreme caching and takes up a ton of memory if you use it**.
?
You mean it take much more RAM when using res/raw ? But why is it this way? Is it true for all Android versions? Is it always recommended to avoid using res/raw, and use assets folder instead? If so, shouldn't Google suggest such a thing in the IDE then?
But they talk about taking it from Jar, not from resource folder. Or is it the same?
And, is there any way to make it use the timezones set by the OS, if it's API 26 and above, so that it won't need to load it from a file at all?
I've now tested on my device (Nexus 5x with Android 8.1), and here are the results of testing assets vs raw :
using original call of AndroidThreeTen.init(this)
:
Before call: used 1.4 MB
After call: used 2.4 MB
using function of originalLoading
:
Before call:1.5 MB
After call: 2.5 MB
I don't see much difference here. On some cases I've ran it, one of them took a tiny bit more, and on others the other. Maybe it got optimized on Android 8.1 or somewhere below?
Maybe it's one of the optimizations they did, that make it now hard to notice, like what they did with Bitmaps (I wrote about it here) ?
Then again, my way of measuring might not be so accurate, as it's tricky to measure memory on Java world...
Here's my POC to test it:
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val handler = Handler()
System.gc()
handler.postDelayed( {
Log.d("AppLog", "heap mem before:" + getHeapMemStats(this) )
// AndroidThreeTen.init(this)
originalLoading()
System.gc()
handler. postDelayed({
Log.d("AppLog", "heap mem after:" + getHeapMemStats(this) )
}, 1000)
}, 1000)
}
fun getHeapMemStats(context: Context): String {
val runtime = Runtime.getRuntime()
val maxMemInBytes = runtime.maxMemory()
val availableMemInBytes = runtime.maxMemory() - (runtime.totalMemory() - runtime.freeMemory())
val usedMemInBytes = maxMemInBytes - availableMemInBytes
val usedMemInPercentage = usedMemInBytes * 100 / maxMemInBytes
return "used: " + Formatter.formatShortFileSize(context, usedMemInBytes) + " / " +
Formatter.formatShortFileSize(context, maxMemInBytes) + " (" + usedMemInPercentage + "%)"
}
Which Android version do you have? Can you test it on older Android versions, maybe?
from threetenabp.
Related Issues (20)
- Add Usage info HOT 1
- DateTimeParseException when parse HOT 4
- Update tzdb.dat to new version. HOT 3
- Duplicate ThreeTen Classes in AndroidTest HOT 2
- Calculation problem HOT 4
- IllegalStateException: Already initialized HOT 14
- minusDays() returns wrong date for specific use case HOT 2
- R8 issue with Ser HOT 14
- Contribution: Gson.toJson with @Expose annotations error HOT 1
- Will we still need this library after java.time will be desugared? HOT 6
- Do I actually want to switch to desugared native apis? HOT 7
- Wrong Format OffsetDateTime HOT 1
- Bug in DateTimeFormatter - Wrong year. HOT 1
- Help for specific pattern HOT 1
- Support Compose Preview HOT 2
- Wrong time zone offset HOT 1
- NoClassDefFoundError in android 4.4 even with multidex enabled HOT 2
- Returns the Value to 1926 HOT 3
- Please *do not* consider switching to core library desugaring HOT 2
- Fatal Exception: n30.g Unknown time-zone ID: America/Ciudad_Juarez HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from threetenabp.