question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Overly aggressive inlining of Date expressions

See original GitHub issue

Consider this JavaScript code:

console.log(
  (function() {
    var start = new Date().getTime();
    var end = new Date().getTime();
    return end - start;
  })()
);

Passing this through advanced optimizations yields

console.log((new Date).getTime()-(new Date).getTime());

which has different semantics: The unoptimized version will calculate an end date after the start date, and the difference will be non-negative. The optimized version will evaluate left to right, calculating the left date first, followed by the right date, producing non-positive values.

Example, using Nashorn:

jjs> (new Date).getTime()-(new Date).getTime()
-3

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:4
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
mfikescommented, Sep 20, 2018

@lazarljubenovic Yep, it is the result of a different optimization. This was found via ClojureScript, which can dynamically generate code (via a macro) to measure the length of time needed to evaluate an expression. If the thing you are measuring turns out to be trivial and gets (correctly) elided during advanced, then the inlining issue crops up.

0reactions
EatingWcommented, May 29, 2019

Created internal issue http://b/133856418

Read more comments on GitHub >

github_iconTop Results From Across the Web

c++ - What happens if function inlining is too aggressive?
What effect should I expect from having functions inlined overly aggressively and having one hundred times bigger executable?
Read more >
c# - Is there a downside to using AggressiveInlining on simple ...
3) Inlining too much means the code becomes larger, and might not fit into caches anymore. Cache misses can be a significant performance...
Read more >
A Deeper Look at Inline Functions - ACCU.org
Some compilers have an auto-inline function that lets the compiler decide which functions to inline and which to leave as is. Of course,...
Read more >
Proposal: Mid-stack inlining in the Go compiler
Thus, even without aggressive inlining, the user might see inaccurate tracebacks due to inlining. To mitigate this problem somewhat, the Go 1.8 ...
Read more >
performance | Dave Cheney
Even taking into account the opportunities for further optimisation, aggressive inlining tends to increase the size of, and the time too compile, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found