Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Looking for more performance
Message
From
15/04/2016 01:23:58
 
 
To
14/04/2016 17:51:30
General information
Forum:
Javascript
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
01634763
Message ID:
01634828
Views:
29
It would be logical......

>Almost sure that JS (pre)compiler optimizes constant
>
>
>>Must admit I'm a bit vague on the behaviour of constants within a method. IAC I think the main cause of slowness will be in updating the DOM.
>>
>>Found myself wondering how an angular directive might fare in this scenario ?
>>
>>>Doing calculations in else definately is smarter, did not really look at code ;-)
>>>But I guess const being scoped for function level could lead to 1 allocation on "variable" stack of the fuction and perhaps 1 assignment on each run ( could be optimized away if each function as an object is considered an immutable object similar to strings in C# or Java runtimes, then const could be a RO property of the function similar to python "variables" in a dict of functon level) - hoisting the constant strings to an object or array outside the function and only accessing it should be minimally faster as this should provide a caching effect - even if variable lookup should take minimally longer as another scope has to be searched, it should be faster then re-setting the const in each function call.
>>>
>>>
>>>>>Something is very slow here if I have about 200 items on the page. I would have expected that to slow around 40,000. Anyone would have an idea on how to optimize this logic to avoid this javascript latency?
>>>>
>>>>Seems to me you are doing some calculations unnecessarily (e.g current date every time, hours, minutes and seconds when only day is of interest). Also I think the calculations themselves could be simplified. This looks shorter:
function SinceWhen(receivedDate, currentDate, language) {
>>>>            const ONE_SECOND = 1000;
>>>>            const ONE_MINUTE = ONE_SECOND * 60;
>>>>            const ONE_HOUR = ONE_MINUTE * 60;
>>>>            const ONE_DAY = ONE_HOUR * 24;
>>>>
>>>>            const SECOND = "second";
>>>>            const MINUTE = "minute";
>>>>            const HOUR = "hour";
>>>>            const DAY = "day";
>>>>            const NOW = "Just now";
>>>>            const YESTERDAY = "Yesterday";
>>>>
>>>>
>>>>        }
Not properly tested :-} Not dealing with the language issue (which could be handled in the getString() method) But I'm not sure it would improve performance - manipulating the DOM is probably taking most of the time.
Previous
Reply
Map
View

Click here to load this message in the networking platform