Skip to content

Commit c7ececa

Browse files
flimzydmitshur
authored andcommitted
compiler: Do not generate unused $ptr local variable. (#690)
The $ptr variable in every output function appears never to be used, so this eliminates it. It's an obsolete hold-over from a previous change. It appears it was added in df432fe, where it was referenced in compiler/expressions.go, but then a few days later with 923aee9, that reference was removed, but the original declaration was left behind. By not adding $ptr to the c.localVars list, it is neither set nor read. It is not used anywhere else. Background I noticed while playing with `uglifyjs`, a ton of warnings such as: WARN: Dropping unused variable $ptr [main.js:95,666198] WARN: Dropping unused variable $ptr [main.js:95,667947] Which piqued my curiosity, to see if GopherJS could possibly be made intelligent enough to eliminate this $ptr value from the output when it's not used. Looking at the output of one of my compiled projects, I saw many examples such as: Object.ptr.prototype.Get = function(key) { var $ptr, key, o; o = this; return o.object[$externalize(key, $String)]; }; Some grepping further revealed that the only time we ever set the variable is in lines such as: /* */ } return; } if ($f === undefined) { $f = { $blk: Cond.ptr.prototype.Wait }; } $f.$ptr = $ptr; $f._r = _r; $f.c = c; $f.$s = $s; $f.$r = $r; return $f; Which is just restoring the function state after returning from a possibly-blocking function call. I found no other use of this variable, so I removed it, and re-compiled my project, both with and without the -m flag, and got the following size reductions: | Build command | Original bytes | After bytes | Savings (%) | |-------------------|---------------:|-------------:|----------------:| | gopherjs build | 11,743,976 | 11,608,077 | 135,899 (1.16%) | | gopherjs build -m | 7,634,995 | 7,523,944 | 111,051 (1.45%) |
1 parent 38c2151 commit c7ececa

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

compiler/package.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -674,7 +674,7 @@ func translateFunction(typ *ast.FuncType, recv *ast.Ident, body *ast.BlockStmt,
674674
parent: outerContext,
675675
sig: sig,
676676
allVars: make(map[string]int, len(outerContext.allVars)),
677-
localVars: []string{"$ptr"},
677+
localVars: []string{},
678678
flowDatas: map[*types.Label]*flowData{nil: {}},
679679
caseCounter: 1,
680680
labelCases: make(map[*types.Label]int),

0 commit comments

Comments
 (0)