airsdk / Adobe-Runtime-Support

Report, track and discuss issues in Adobe AIR. Monitored by Adobe - and HARMAN - and maintained by the AIR community.
206 stars 11 forks source link

[Android][iOS][macOS] DateTimeFormatter.format low performance #99

Open itlancer opened 5 years ago

itlancer commented 5 years ago

Problem Description

Format Date via DateTimeFormatter.format method has extremely low performance. Each method call takes about 5 ms with mass market tablets, phones and TV boxes. With this issue DateTimeFormatter.format method completely unusable with low-end Android devices. We need to show date and time fields in our multi language application, but if we use this method application frame rate down to 5-10 FPS with some devices.

It has been tested with many different AIR versions even with latests AIR 32.0.0.144 beta and AIR 33.0.1.228 with different Android, iOS, macOS devices with different OSes versions an different architectures. Same problem in all cases. armv8 Android apps builds have better performance than armv7 with such cases. That works fine with Windows.

Tracker issue: https://tracker.adobe.com/#/view/AIR-3984753

Steps to Reproduce

Try to format Date object via DateTimeFormatter.format method. Application example call "format" method every frame and trace and display execution time at top-left corner of application. Application example with sources attached. date_time_formatter_performance_bug.zip

package {
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.text.TextField;
    import flash.utils.getTimer;
    import flash.globalization.DateTimeFormatter;
    import flash.globalization.LocaleID;

    public class DateTimeFormatterPerformanceBug extends Sprite {
        private var textField:TextField;
        private var dateTimeFormatter:DateTimeFormatter;

        public function DateTimeFormatterPerformanceBug() {
            addEventListener(Event.ADDED_TO_STAGE, init);
        }

        private function init(e:Event):void {
            removeEventListener(Event.ADDED_TO_STAGE, init);

            textField = new TextField();
            addChild(textField);

            dateTimeFormatter = new DateTimeFormatter(LocaleID.DEFAULT);
            dateTimeFormatter.setDateTimePattern("HH:mm:ss");

            addEventListener(Event.ENTER_FRAME, enterFrame);
        }

        private function enterFrame(e:Event):void {
            var date:Date = new Date();
            var time:uint = getTimer();
            dateTimeFormatter.format(date);//This line takes a lot of CPU time
            textField.text = (getTimer() - time).toString();
            trace(textField.text);
        }
    }
}

Actual Result: DateTimeFormatter.format takes about 2 ms with hight-end devices (Android, iOS, macOS) and about 5-8 ms with low-end devices that cause performance lags and FPS drops.

Expected Result: DateTimeFormatter.format should has better performance and takes about 0-1 ms as with Windows devices.

Known Workarounds

none

ajwfrost commented 5 years ago

Found this curious as the code that does the formatting is platform-independent - but uses a third party library. We'll do some extra profiling and see whether we can speed this up on Android..

ajwfrost commented 5 years ago

Looked into this a little more, the code does end up calling back into the Android Java layer to do the work, but there are some inefficiencies in here so we should be able to optimise this a bit..

itlancer commented 4 years ago

This issue still exists with latest AIR 33.1.1.50.