From 911f456a18197c0ea7a558a95f86486a3dfc173c Mon Sep 17 00:00:00 2001 From: Matthias Radestock Date: Fri, 28 Apr 2017 23:43:35 +0100 Subject: [PATCH 1/2] make Node.WithTableTruncationInformation private It is not used elsewhere and is rather specialised. --- report/table.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/report/table.go b/report/table.go index accdd6553..10177d5c8 100644 --- a/report/table.go +++ b/report/table.go @@ -20,8 +20,8 @@ const ( PropertyListType = "property-list" ) -// WithTableTruncationInformation appends table truncation info to the node, returning the new node. -func (node Node) WithTableTruncationInformation(prefix string, totalRowsCount int) Node { +// withTableTruncationInformation appends table truncation info to the node, returning the new node. +func (node Node) withTableTruncationInformation(prefix string, totalRowsCount int) Node { if totalRowsCount > MaxTableRows { truncationCount := fmt.Sprintf("%d", totalRowsCount-MaxTableRows) node = node.WithLatest(TruncationCountPrefix+prefix, mtime.Now(), truncationCount) @@ -43,7 +43,7 @@ func (node Node) AddPrefixMulticolumnTable(prefix string, rows []Row) Node { } addedRowsCount++ } - return node.WithTableTruncationInformation(prefix, len(rows)) + return node.withTableTruncationInformation(prefix, len(rows)) } // AddPrefixPropertyList appends arbitrary key-value pairs to the Node, returning a new node. @@ -56,7 +56,7 @@ func (node Node) AddPrefixPropertyList(prefix string, propertyList map[string]st node = node.WithLatest(prefix+label, mtime.Now(), value) addedPropertiesCount++ } - return node.WithTableTruncationInformation(prefix, len(propertyList)) + return node.withTableTruncationInformation(prefix, len(propertyList)) } // WithoutPrefix returns the string with trimmed prefix and a From 17b88b4110f02d7b71506923b4a10754e182b04c Mon Sep 17 00:00:00 2001 From: Matthias Radestock Date: Fri, 28 Apr 2017 23:54:24 +0100 Subject: [PATCH 2/2] eliminate excessive calls to mtime.Now() This isn't going to noticeably improve performance, but enables future optimisations, e.g. more compact representations of LatestMaps where many/all entries share the same timestamp. --- report/table.go | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/report/table.go b/report/table.go index 10177d5c8..134388803 100644 --- a/report/table.go +++ b/report/table.go @@ -21,16 +21,17 @@ const ( ) // withTableTruncationInformation appends table truncation info to the node, returning the new node. -func (node Node) withTableTruncationInformation(prefix string, totalRowsCount int) Node { +func (node Node) withTableTruncationInformation(prefix string, totalRowsCount int, now time.Time) Node { if totalRowsCount > MaxTableRows { truncationCount := fmt.Sprintf("%d", totalRowsCount-MaxTableRows) - node = node.WithLatest(TruncationCountPrefix+prefix, mtime.Now(), truncationCount) + node = node.WithLatest(TruncationCountPrefix+prefix, now, truncationCount) } return node } // AddPrefixMulticolumnTable appends arbitrary rows to the Node, returning a new node. func (node Node) AddPrefixMulticolumnTable(prefix string, rows []Row) Node { + now := mtime.Now() addedRowsCount := 0 for _, row := range rows { if addedRowsCount >= MaxTableRows { @@ -39,24 +40,25 @@ func (node Node) AddPrefixMulticolumnTable(prefix string, rows []Row) Node { // Add all the row values as separate entries for columnID, value := range row.Entries { key := strings.Join([]string{row.ID, columnID}, TableEntryKeySeparator) - node = node.WithLatest(prefix+key, mtime.Now(), value) + node = node.WithLatest(prefix+key, now, value) } addedRowsCount++ } - return node.withTableTruncationInformation(prefix, len(rows)) + return node.withTableTruncationInformation(prefix, len(rows), now) } // AddPrefixPropertyList appends arbitrary key-value pairs to the Node, returning a new node. func (node Node) AddPrefixPropertyList(prefix string, propertyList map[string]string) Node { + now := mtime.Now() addedPropertiesCount := 0 for label, value := range propertyList { if addedPropertiesCount >= MaxTableRows { break } - node = node.WithLatest(prefix+label, mtime.Now(), value) + node = node.WithLatest(prefix+label, now, value) addedPropertiesCount++ } - return node.withTableTruncationInformation(prefix, len(propertyList)) + return node.withTableTruncationInformation(prefix, len(propertyList), now) } // WithoutPrefix returns the string with trimmed prefix and a