mirror of
https://github.com/soypat/lneto.git
synced 2026-08-21 23:19:03 +00:00
Reduce heap allocs 2 (#46)
* reduce heap allocations in tcp logging; omit use of AppendFloat which allocates a metric sh*tton * debugheaplog: better heap statistic logging * heap: use string for pcap.Frame.Protocol * add potential to eliminate Flags.String heap alloc, remove incorrect HEAP comments * add StackAsync.DebugErr and httpraw.SetBytes * many heap alloc reductions and replacement of bytes.Equal with internal.BytesEqual
This commit is contained in:
@@ -15,9 +15,6 @@ const (
|
||||
)
|
||||
|
||||
var (
|
||||
memstats runtime.MemStats
|
||||
lastAllocs uint64
|
||||
|
||||
timebuf [len(timefmt) * 2]byte
|
||||
)
|
||||
|
||||
@@ -28,12 +25,7 @@ func LogEnabled(l *slog.Logger, lvl slog.Level) bool {
|
||||
func LogAttrs(_ *slog.Logger, level slog.Level, msg string, attrs ...slog.Attr) {
|
||||
now := time.Now()
|
||||
n := len(now.AppendFormat(timebuf[:0], timefmt))
|
||||
runtime.ReadMemStats(&memstats)
|
||||
if memstats.TotalAlloc != lastAllocs {
|
||||
print("[ALLOC] inc=", int64(memstats.TotalAlloc)-int64(lastAllocs))
|
||||
print(" tot=", memstats.TotalAlloc, " seqs")
|
||||
println()
|
||||
}
|
||||
LogAllocs(msg)
|
||||
print("time=", unsafe.String(&timebuf[0], n), " ")
|
||||
if level == LevelTrace {
|
||||
print("TRACE ")
|
||||
@@ -57,8 +49,12 @@ func LogAttrs(_ *slog.Logger, level slog.Level, msg string, attrs ...slog.Attr)
|
||||
}
|
||||
}
|
||||
println()
|
||||
allocmu.Lock()
|
||||
runtime.ReadMemStats(&memstats)
|
||||
if memstats.TotalAlloc != lastAllocs {
|
||||
lastAllocs = memstats.TotalAlloc
|
||||
if lastAllocs != memstats.TotalAlloc {
|
||||
print("alloc increase in heaplog")
|
||||
}
|
||||
lastAllocs = memstats.TotalAlloc
|
||||
lastMallocs = memstats.Mallocs
|
||||
allocmu.Unlock()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user