mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
cmd/compile: remove references to *os.File from ssa package
This reduces the size of the ssa export data by 10%, from 76154 to 67886. It doesn't appear that #20084, which would do this automatically, is going to be fixed soon. Do it manually for now. This speeds up compiling cmd/compile/internal/amd64 and presumably its comrades as well: name old time/op new time/op delta CompileAMD64 89.6ms ± 6% 86.7ms ± 5% -3.29% (p=0.000 n=49+47) name old user-time/op new user-time/op delta CompileAMD64 116ms ± 5% 112ms ± 5% -3.51% (p=0.000 n=45+42) name old alloc/op new alloc/op delta CompileAMD64 26.7MB ± 0% 25.8MB ± 0% -3.26% (p=0.008 n=5+5) name old allocs/op new allocs/op delta CompileAMD64 223k ± 0% 213k ± 0% -4.46% (p=0.008 n=5+5) Updates #20084 Change-Id: I49e8951c5bfce63ad2b7f4fc3bfa0868c53114f9 Reviewed-on: https://go-review.googlesource.com/41493 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
parent
cdeda796c7
commit
4ee934ad27
3 changed files with 20 additions and 14 deletions
|
|
@ -8,11 +8,17 @@ import (
|
||||||
"cmd/internal/src"
|
"cmd/internal/src"
|
||||||
"crypto/sha1"
|
"crypto/sha1"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
"math"
|
"math"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type writeSyncer interface {
|
||||||
|
io.Writer
|
||||||
|
Sync() error
|
||||||
|
}
|
||||||
|
|
||||||
// A Func represents a Go func declaration (or function literal) and its body.
|
// A Func represents a Go func declaration (or function literal) and its body.
|
||||||
// This package compiles each Func independently.
|
// This package compiles each Func independently.
|
||||||
// Funcs are single-use; a new Func must be created for every compiled function.
|
// Funcs are single-use; a new Func must be created for every compiled function.
|
||||||
|
|
@ -30,7 +36,7 @@ type Func struct {
|
||||||
|
|
||||||
// Given an environment variable used for debug hash match,
|
// Given an environment variable used for debug hash match,
|
||||||
// what file (if any) receives the yes/no logging?
|
// what file (if any) receives the yes/no logging?
|
||||||
logfiles map[string]*os.File
|
logfiles map[string]writeSyncer
|
||||||
HTMLWriter *HTMLWriter // html writer, for debugging
|
HTMLWriter *HTMLWriter // html writer, for debugging
|
||||||
DebugTest bool // default true unless $GOSSAHASH != ""; as a debugging aid, make new code conditional on this and use GOSSAHASH to binary search for failing cases
|
DebugTest bool // default true unless $GOSSAHASH != ""; as a debugging aid, make new code conditional on this and use GOSSAHASH to binary search for failing cases
|
||||||
|
|
||||||
|
|
@ -590,7 +596,7 @@ func (f *Func) DebugHashMatch(evname, name string) bool {
|
||||||
|
|
||||||
func (f *Func) logDebugHashMatch(evname, name string) {
|
func (f *Func) logDebugHashMatch(evname, name string) {
|
||||||
if f.logfiles == nil {
|
if f.logfiles == nil {
|
||||||
f.logfiles = make(map[string]*os.File)
|
f.logfiles = make(map[string]writeSyncer)
|
||||||
}
|
}
|
||||||
file := f.logfiles[evname]
|
file := f.logfiles[evname]
|
||||||
if file == nil {
|
if file == nil {
|
||||||
|
|
@ -604,8 +610,7 @@ func (f *Func) logDebugHashMatch(evname, name string) {
|
||||||
}
|
}
|
||||||
f.logfiles[evname] = file
|
f.logfiles[evname] = file
|
||||||
}
|
}
|
||||||
s := fmt.Sprintf("%s triggered %s\n", evname, name)
|
fmt.Fprintf(file, "%s triggered %s\n", evname, name)
|
||||||
file.WriteString(s)
|
|
||||||
file.Sync()
|
file.Sync()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ import (
|
||||||
|
|
||||||
type HTMLWriter struct {
|
type HTMLWriter struct {
|
||||||
Logger
|
Logger
|
||||||
*os.File
|
w io.WriteCloser
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewHTMLWriter(path string, logger Logger, funcname string) *HTMLWriter {
|
func NewHTMLWriter(path string, logger Logger, funcname string) *HTMLWriter {
|
||||||
|
|
@ -23,7 +23,7 @@ func NewHTMLWriter(path string, logger Logger, funcname string) *HTMLWriter {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Fatalf(src.NoXPos, "%v", err)
|
logger.Fatalf(src.NoXPos, "%v", err)
|
||||||
}
|
}
|
||||||
html := HTMLWriter{File: out, Logger: logger}
|
html := HTMLWriter{w: out, Logger: logger}
|
||||||
html.start(funcname)
|
html.start(funcname)
|
||||||
return &html
|
return &html
|
||||||
}
|
}
|
||||||
|
|
@ -299,11 +299,11 @@ func (w *HTMLWriter) Close() {
|
||||||
if w == nil {
|
if w == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
w.WriteString("</tr>")
|
io.WriteString(w.w, "</tr>")
|
||||||
w.WriteString("</table>")
|
io.WriteString(w.w, "</table>")
|
||||||
w.WriteString("</body>")
|
io.WriteString(w.w, "</body>")
|
||||||
w.WriteString("</html>")
|
io.WriteString(w.w, "</html>")
|
||||||
w.File.Close()
|
w.w.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
// WriteFunc writes f in a column headed by title.
|
// WriteFunc writes f in a column headed by title.
|
||||||
|
|
@ -328,13 +328,13 @@ func (w *HTMLWriter) WriteColumn(title string, html string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *HTMLWriter) Printf(msg string, v ...interface{}) {
|
func (w *HTMLWriter) Printf(msg string, v ...interface{}) {
|
||||||
if _, err := fmt.Fprintf(w.File, msg, v...); err != nil {
|
if _, err := fmt.Fprintf(w.w, msg, v...); err != nil {
|
||||||
w.Fatalf(src.NoXPos, "%v", err)
|
w.Fatalf(src.NoXPos, "%v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *HTMLWriter) WriteString(s string) {
|
func (w *HTMLWriter) WriteString(s string) {
|
||||||
if _, err := w.File.WriteString(s); err != nil {
|
if _, err := io.WriteString(w.w, s); err != nil {
|
||||||
w.Fatalf(src.NoXPos, "%v", err)
|
w.Fatalf(src.NoXPos, "%v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ package ssa
|
||||||
import (
|
import (
|
||||||
"cmd/internal/obj"
|
"cmd/internal/obj"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
"math"
|
"math"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
@ -561,7 +562,7 @@ func logRule(s string) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var ruleFile *os.File
|
var ruleFile io.Writer
|
||||||
|
|
||||||
func min(x, y int64) int64 {
|
func min(x, y int64) int64 {
|
||||||
if x < y {
|
if x < y {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue