Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

let vs var generates a lot more instructions #800

Open
Cellule opened this issue Apr 13, 2016 · 4 comments
Open

let vs var generates a lot more instructions #800

Cellule opened this issue Apr 13, 2016 · 4 comments

Comments

@Cellule
Copy link
Contributor

Cellule commented Apr 13, 2016

Sorry in advance I haven't been able to get a simpler repro case at this time.
My test case is the following

const n = 500;
function getTest(name) {
  var fn;
  eval(`fn = function memcopy_${name}(a, b, start, end) {for (let i = start; i < end; i++) { b[i] = a[i]; }}`);
  return fn
}
var foo = getTest("Int8")
var src = new Int8Array(n);
src.fill(1);
var dst = new Int8Array(n);
foo(src, dst, 0, 250);
foo(src, dst, 250, n);

This code generates the following IR

Function Entry
    s7.var          =  NewBlockScope                                          #0000 
    s15(s7->i)<?,,--,s?,s?>.var = InitLetFld  0xXXXXXXXX (null)[PrimitiveOrObject].var #0002 
Every uses of `i`
    s19.var         =  LdSlotArr      s17(s7[2]).var                          #0017 
    s8.var          =  LdSlot         s20(s19[0])<?,,--,s?,s?>.var            #0017 

This IR makes it hard to make proper optimizations (in this case Array optimizations).

If we change the let keyword for a var, i becomes a regular variable.
Is it possible to make let variables behave exactly the same as a regular var if there is no redefinition inside the function ?
Should this be done at Bytecode level, IR Builder or Globopt ?

@pleath
Copy link
Contributor

pleath commented Apr 13, 2016

The fact that the code is in eval is the limiting factor for us, right? We could theoretically make the eval code gen close enough to non-eval code to make the optimizer’s life easier, but it would take some effort. Is this a synthetic test case?

--Paul

From: Michael Ferris [mailto:[email protected]]
Sent: Wednesday, April 13, 2016 11:27 AM
To: Microsoft/ChakraCore [email protected]
Subject: [Microsoft/ChakraCore] let vs var generates a lot more instructions (#800)

Sorry in advance I haven't been able to get a simpler repro case at this time.
My test case is the following

const n = 500;

function getTest(name) {

var fn;

eval(fn = function memcopy_${name}(a, b, start, end) {for (let i = start; i < end; i++) { b[i] = a[i]; }});

return fn

}

var foo = getTest("Int8")

var src = new Int8Array(n);

src.fill(1);

var dst = new Int8Array(n);

foo(src, dst, 0, 250);

foo(src, dst, 250, n);

This code generates the following IR

Function Entry

s7.var          =  NewBlockScope                                          #0000

s15(s7->i)<?,,--,s?,s?>.var = InitLetFld  0xXXXXXXXX (null)[PrimitiveOrObject].var #0002

Every uses of i

s19.var         =  LdSlotArr      s17(s7[2]).var                          #0017

s8.var          =  LdSlot         s20(s19[0])<?,,--,s?,s?>.var            #0017

This IR makes it hard to make proper optimizations (in this case Array optimizations).

If we change the let keyword for a var, i becomes a regular variable.
Is it possible to make let variables behave exactly the same as a regular var if there is no redefinition inside the function ?
Should this be done at Bytecode level, IR Builder or Globopt ?


You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHubhttps://github.com//issues/800

@Cellule
Copy link
Contributor Author

Cellule commented Apr 13, 2016

I'm not entirely sure, but it's true that I haven't been able to repro outside of eval.
I wrote that test case, to type specialize each function differently.
Regardless, this means that let (and possibly const) inside of eval will always be much slower than var

@ianwjhalliday
Copy link
Collaborator

I don't see why we need to make a scope object for the for loop's scope in this case. Doesn't matter that it is in an eval, there is no nested eval nor any capture.

@pleath
Copy link
Contributor

pleath commented Apr 14, 2016

Right, that's why I say that it's theoretically possible to fix this. My only question is the priority relative to RS1 bugs.

-- Paul


From: Ian Hallidaymailto:[email protected]
Sent: ‎4/‎13/‎2016 7:17 PM
To: Microsoft/ChakraCoremailto:[email protected]
Cc: Paul Leathersmailto:[email protected]
Subject: Re: [Microsoft/ChakraCore] let vs var generates a lot more instructions (#800)

I don't see why we need to make a scope object for the for loop's scope in this case. Doesn't matter that it is in an eval, there is no nested eval nor any capture.


You are receiving this because you commented.
Reply to this email directly or view it on GitHubhttps://github.com//issues/800#issuecomment-209724601

@curtisman curtisman added this to the Backlog milestone May 18, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants