Performance measurements: Parsing dates #2740
westnordost
started this conversation in
General
Replies: 3 comments 21 replies
-
I think you've mixed up the numbers somewhere, because in the graphs, the 2019 phone is slower than the 2013 phone. |
Beta Was this translation helpful? Give feedback.
1 reply
-
Some questions that make me feel a bit stupid...
|
Beta Was this translation helpful? Give feedback.
7 replies
-
How did you let it run on multiple cores?
…On April 15, 2021 11:28:06 AM GMT+02:00, Helium314 ***@***.***> wrote:
So... finally results on my phones running Lineage 16.0:>
S4 Mini has a Snapdragon 400 (1.7 GHz, dual core)>
S4 Mini Plus has a Snapdragon 410 (1.2 GHz, quad core)>
>
method | S4 Mini, 1 core | S4 Mini, 2 cores | S4 Mini Plus, 1 core | S4
Mini Plus, 4 cores>
--|--|--|--|-->
Naïve (and wrong), using substring (no validation) | 1 μs | 1 μs | 2 µs
| 1 µs>
Naïve (and wrong), using a regex | 63 μs | 51 μs | 61 µs | 39 µs>
GregorianCalendar, using substring (no validation) | 25 μs | 13 μs | 20
µs | 11 µs>
GregorianCalendar, using a regex | 94 μs | 66 μs | 80 µs | 56 µs>
SimpleDateFormat | 82 µs | 62 μs | 67 µs | 53 µs>
LocalDateTime.parse | 33 μs | 32 μs | 30 µs | 28 µs>
Instant.parse | 55 μs | 55 μs | 46 µs | 42 µs>
>
`Naïve (and wrong), using substring (no validation)` sometimes takes
significantly longer. On both phones I ran the tests multiple times and
each had one run where this method took 6 or 7 µs.>
Other tests are reproducible within ca 10%.>
>
If someone want to run the test, simply extract and install the
attached
[app](https://github.com/streetcomplete/StreetComplete/files/6316534/date_parse_test.zip).
Start app, click `start test` and wait (up to) a few minutes (nothing
else in this app is actually working).>
The last two tests require Android 8 and will not appear on older
versions.>
>
-- >
You are receiving this because you authored the thread.>
Reply to this email directly or view it on GitHub:>
#2740 (reply in thread)
--
Diese Nachricht wurde von meinem Android-Gerät mit K-9 Mail gesendet.
|
Beta Was this translation helpful? Give feedback.
13 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Recently I mentioned that parsing dates in Java is quite slow and that 50% of the total parsing time of OpenStreetMap map data is spent on parsing the dates.
I advertised to do this bigger refactor #2678 because then this would be a good opportunity to get rid of the
SimpleDateFormat
parsing and use the more performantkotlinx-datetime
, which is based on the Java 8 time API, also available on Android (if certain build configurations are made).So, I now did a measurement to see how slow or fast exactly each method is. Here it is:
Android 10
(2019)
Android 9
(2015)
Android 9
(2013)
Android 5.1
(2013)
GregorianCalendar
, using substring (no validation)GregorianCalendar
, using a regexSimpleDateFormat
LocalDateTime.parse
Instant.parse
And yeah, even 180 μs appears little, but let's parse 30000 OpenStreetMap elements which each have a date attached and we are at 5.4 seconds for the date parsing alone.
That old 5-7 years old mid-range phones are significantly slower than a relatively recent high-end phone is no surprise.
The naïve (and wrong) parsing that simply splits up the date string is each the bottom-line, it is pretty much not possible to make it any faster than that.
There are two observations:
Instant
) is 20% to 100% faster, depending on the phone / Android version.SimpleDateFormat
(old Java time API) is consistently the slowest.Date
,SimpleDateFormat
). Could have other reaons of course.Conclusion
Migrating to
kotlinx-datetime
which uses the Java 8 time API (using theInstant.parse
method) will reduce date parsing time by 10%-50%, for older devices possibly more.This then will result in a decrease of download times by up to 25%. So, a download that took 20 seconds before will then take just 14 seconds. It will not really have any effect on anything else because that is the only place in the app where dates are parsed (en mass).
Not to mention, this is something that needs to be done anyway if one day an iOS version was made (#1892).
Code
Code used for measuring this
Beta Was this translation helpful? Give feedback.
All reactions