Skip to content

Commit

Permalink
Merge pull request #22 from msaf1980/gtags
Browse files Browse the repository at this point in the history
Gtags: some fix/optimization
  • Loading branch information
msaf1980 authored Mar 18, 2023
2 parents ee1bf7e + 978665c commit 528eed3
Show file tree
Hide file tree
Showing 25 changed files with 1,661 additions and 352 deletions.
16 changes: 11 additions & 5 deletions .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:

- name: Benchmark (PR)
run: |
set -euo pipefail; for i in {1..5}; do
set -euo pipefail; for i in {1..6}; do
echo STEP ${i}
go test ./... -benchmem -run=^$ -bench '^Benchmark' | tee -a ${{ env.TMP_DIR }}/bench-pr.txt
done
Expand All @@ -50,7 +50,7 @@ jobs:

- name: Benchmark (Base)
run: |
set -euo pipefail; for i in {1..5}; do
set -euo pipefail; for i in {1..6}; do
echo STEP ${i}
go test ./... -benchmem -run=^$ -bench '^Benchmark' | tee -a ${{ env.TMP_DIR }}/bench-base.txt
done
Expand All @@ -59,15 +59,21 @@ jobs:
run: |
cp ${{ env.TMP_DIR }}/bench-base.txt ${{ env.TMP_DIR }}/bench-pr.txt .
set -euo pipefail
qbenchstat -increasing 'match/s' -threshold 2 -format html bench-base.txt bench-pr.txt > ${{ env.TMP_DIR }}/benchcmp.html
#qbenchstat -increasing 'match/s' -format html bench-base.txt bench-pr.txt | tee benchcmp-${{ matrix.go-version }}.html
qbenchstat -increasing 'match/s' -threshold 2 -format html bench-base.txt bench-pr.txt > ${{ env.TMP_DIR }}/benchstat.html
qbenchstat -increasing 'match/s' -format html bench-base.txt bench-pr.txt > benchstat-${{ matrix.go-version }}.html
- name: Upload Benchstat
uses: actions/upload-artifact@v2
with:
name: benchstat
path: benchstat-${{ matrix.go-version }}.html

- name: Create comment PR
run: |
echo 'Benchmark comparison for golang ${{ matrix.go-version }} on [${{ github.event.pull_request.head.sha }}](${{ github.event.repository.html_url }}/commit/${{ github.event.pull_request.head.sha }}) (${{ github.event.pull_request.head.ref }}) vs [${{ github.event.pull_request.base.sha }}](${{ github.event.repository.html_url }}/commit/${{ github.event.pull_request.base.sha }}) (${{ github.event.pull_request.base.ref }})' > ${{ env.TMP_DIR }}/pr_comment
echo "<details><summary>Benchmark diff</summary>" >> ${{ env.TMP_DIR }}/pr_comment
cat ${{ env.TMP_DIR }}/benchcmp.html >> ${{ env.TMP_DIR }}/pr_comment
cat ${{ env.TMP_DIR }}/benchstat.html >> ${{ env.TMP_DIR }}/pr_comment
echo "</details>" >> ${{ env.TMP_DIR }}/pr_comment
# echo "<details><summary>Benchmark result</summary>" >> ${{ env.TMP_DIR }}/pr_comment
Expand Down
50 changes: 10 additions & 40 deletions gglob/gtree.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,13 @@ import (
type GTreeItem struct {
Item *glob.Glob

Terminate bool
Terminated string // end of chain (resulting raw/normalized globs)
TermIndex int // rule num of end of chain (resulting glob), can be used in specific cases
items.Terminated

// TODO: may be some ordered tree for complete string nodes search speedup (on large set) ?
ChildsMap map[string]*GTreeItem // full match
Childs []*GTreeItem // next possible parts slice
}

func (item *GTreeItem) append(globs *[]string, index *[]int, first items.Store) {
if globs != nil {
*globs = append(*globs, item.Terminated)
}
if index != nil {
*index = append(*index, item.TermIndex)
}
if first != nil {
first.Store(item.TermIndex)
}
}

func (item *GTreeItem) MatchItems(path string, globs *[]string, index *[]int, first items.Store) (matched int) {
var part string
part, path, _ = strings.Cut(path, ".")
Expand All @@ -40,16 +26,8 @@ func (item *GTreeItem) MatchItems(path string, globs *[]string, index *[]int, fi
if len(item.ChildsMap) > 0 {
if child, ok := item.ChildsMap[part]; ok {
if path == "" {
if child.Terminated != "" {
if globs != nil {
*globs = append(*globs, child.Terminated)
}
if index != nil {
*index = append(*index, child.TermIndex)
}
if first != nil {
first.Store(child.TermIndex)
}
if child.Terminate {
child.Append(globs, index, first)
matched++
}
} else {
Expand All @@ -62,16 +40,8 @@ func (item *GTreeItem) MatchItems(path string, globs *[]string, index *[]int, fi
for i := 0; i < len(item.Childs); i++ {
if item.Childs[i].Item.Match(part) {
if path == "" {
if item.Childs[i].Terminated != "" {
if globs != nil {
*globs = append(*globs, item.Childs[i].Terminated)
}
if index != nil {
*index = append(*index, item.Childs[i].TermIndex)
}
if first != nil {
first.Store(item.Childs[i].TermIndex)
}
if item.Childs[i].Terminate {
item.Childs[i].Append(globs, index, first)
matched++
}
} else {
Expand All @@ -90,7 +60,7 @@ func (item *GTreeItem) MatchItemsByParts(parts []string, globs *[]string, index
if child, ok := item.ChildsMap[parts[0]]; ok {
if len(parts) == 1 {
if child.Terminate {
child.append(globs, index, first)
child.Append(globs, index, first)
matched++
}
} else {
Expand All @@ -103,8 +73,8 @@ func (item *GTreeItem) MatchItemsByParts(parts []string, globs *[]string, index
for i := 0; i < len(item.Childs); i++ {
if item.Childs[i].Item.Match(parts[0]) {
if len(parts) == 1 {
if item.Childs[i].Terminated != "" {
item.Childs[i].append(globs, index, first)
if item.Childs[i].Terminate {
item.Childs[i].Append(globs, index, first)
matched++
}
} else {
Expand Down Expand Up @@ -161,8 +131,8 @@ func addGGlob(treeMap map[int]*GTreeItem, gg *GGlob, index int) *GTreeItem {
}

treeItem.Terminate = true
treeItem.Terminated = gg.Node
treeItem.TermIndex = index
treeItem.Query = gg.Node
treeItem.Index = index

return treeItem
}
Expand Down
34 changes: 17 additions & 17 deletions gglob/gtree_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,9 @@ import (
)

type GTreeItemStr struct {
Node string `json:"node"`
Node string

Terminate bool `json:"terminate"`
Terminated string `json:"terminated"` // end of chain (resulting raw/normalized globs)
TermIndex int `json:"term_index"` // rule num of end of chain (resulting glob), can be used in specific cases
Terminated items.Terminated

// TODO: may be some ordered tree for complete string nodes search speedup (on large set) ?
ChildsMap map[string]*GTreeItemStr `json:"childs_map"`
Expand All @@ -30,9 +28,7 @@ func StringGTreeItem(treeItem *GTreeItem) *GTreeItemStr {
}
treeItemStr := &GTreeItemStr{
Node: node,
Terminate: treeItem.Terminate,
Terminated: treeItem.Terminated,
TermIndex: treeItem.TermIndex,
}

if treeItem.Childs != nil {
Expand Down Expand Up @@ -199,15 +195,18 @@ func TestGGlobTree(t *testing.T) {
Node: "*[0-8]",
ChildsMap: map[string]*GTreeItemStr{
"DownEndpointCount": {
Node: "DownEndpointCount",
Terminate: true,
Terminated: "DB.*.{BalanceCluster,BalanceStaging,CoreCluster,EventsCluster,SalesCluster,UpProduction,UpTesting,WebCluster}.*[0-8].DownEndpointCount",
Node: "DownEndpointCount",
Terminated: items.Terminated{
Terminate: true,
Query: "DB.*.{BalanceCluster,BalanceStaging,CoreCluster,EventsCluster,SalesCluster,UpProduction,UpTesting,WebCluster}.*[0-8].DownEndpointCount",
},
},
"UpStatus": {
Node: "UpStatus",
Terminate: true,
Terminated: "DB.*.{BalanceCluster,BalanceStaging,CoreCluster,EventsCluster,SalesCluster,UpProduction,UpTesting,WebCluster}.*[0-8].UpStatus",
TermIndex: 1,
Node: "UpStatus",
Terminated: items.Terminated{
Terminate: true, Index: 1,
Query: "DB.*.{BalanceCluster,BalanceStaging,CoreCluster,EventsCluster,SalesCluster,UpProduction,UpTesting,WebCluster}.*[0-8].UpStatus",
},
},
},
},
Expand All @@ -229,10 +228,11 @@ func TestGGlobTree(t *testing.T) {
Node: "{BalanceCluster,BalanceStaging,CoreCluster,EventsCluster,SalesCluster,UpProduction,UpTesting,WebCluster}",
ChildsMap: map[string]*GTreeItemStr{
"UpStatus": {
Node: "UpStatus",
Terminate: true,
Terminated: "DB.*.{BalanceCluster,BalanceStaging,CoreCluster,EventsCluster,SalesCluster,UpProduction,UpTesting,WebCluster}.UpStatus",
TermIndex: 2,
Node: "UpStatus",
Terminated: items.Terminated{
Terminate: true, Index: 2,
Query: "DB.*.{BalanceCluster,BalanceStaging,CoreCluster,EventsCluster,SalesCluster,UpProduction,UpTesting,WebCluster}.UpStatus",
},
},
},
},
Expand Down
4 changes: 2 additions & 2 deletions glob/tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ func addGlob(rootTree *items.TreeItem, gg *Glob, index int) *items.TreeItem {
}

treeItem.Terminate = true
treeItem.Terminated = gg.Node
treeItem.TermIndex = index
treeItem.Query = gg.Node
treeItem.Index = index

return treeItem
}
Expand Down
32 changes: 22 additions & 10 deletions glob/tree_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package glob

import (
"testing"

"github.com/msaf1980/go-matcher/pkg/items"
)

func TestGlobTree_Group(t *testing.T) {
Expand All @@ -26,17 +28,21 @@ func TestGlobTree_Group(t *testing.T) {
Node: "c", Childs: []*TreeItemStr{
{
Node: "*", Childs: []*TreeItemStr{},
Terminated: "{a?cd*,b*,cd[a-z]}bc*c*e",
TermIndex: 0, Term: true,
Terminated: items.Terminated{
Terminate: true, Index: 0,
Query: "{a?cd*,b*,cd[a-z]}bc*c*e",
},
},
},
},
{
Node: "CD", Childs: []*TreeItemStr{
{
Node: "*", Childs: []*TreeItemStr{},
Terminated: "{a?cd*,b*,cd[a-z]}bc*CD*e",
TermIndex: 1, Term: true,
Terminated: items.Terminated{
Terminate: true, Index: 1,
Query: "{a?cd*,b*,cd[a-z]}bc*CD*e",
},
},
},
},
Expand Down Expand Up @@ -88,26 +94,32 @@ func TestGlobTree_Group(t *testing.T) {
Node: "c", Childs: []*TreeItemStr{
{
Node: "*", Childs: []*TreeItemStr{},
Terminated: "*{a?cd*,b*,cd[a-z]}bc*c*e",
TermIndex: 0, Term: true,
Terminated: items.Terminated{
Terminate: true, Index: 0,
Query: "*{a?cd*,b*,cd[a-z]}bc*c*e",
},
},
},
},
{
Node: "CD", Childs: []*TreeItemStr{
{
Node: "*", Childs: []*TreeItemStr{},
Terminated: "*{a?cd*,b*,cd[a-z]}bc*CD*e",
TermIndex: 1, Term: true,
Terminated: items.Terminated{
Terminate: true, Index: 1,
Query: "*{a?cd*,b*,cd[a-z]}bc*CD*e",
},
},
},
},
{
Node: "cd", Childs: []*TreeItemStr{
{
Node: "*", Childs: []*TreeItemStr{},
Terminated: "*{a?cd*,b*,cd[a-z]}bc*cd*e",
TermIndex: 2, Term: true,
Terminated: items.Terminated{
Terminate: true, Index: 2,
Query: "*{a?cd*,b*,cd[a-z]}bc*cd*e",
},
},
},
},
Expand Down
14 changes: 11 additions & 3 deletions glob/tree_stringlist_opt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package glob

import (
"testing"

"github.com/msaf1980/go-matcher/pkg/items"
)

func TestGlobTree_StringList_Opt(t *testing.T) {
Expand All @@ -19,12 +21,18 @@ func TestGlobTree_StringList_Opt(t *testing.T) {
{
Node: "*", Childs: []*TreeItemStr{
{
Node: "{,b,cd}",
Terminated: "bc.*{,b,cd}", TermIndex: 1, Term: true,
Node: "{,b,cd}",
Terminated: items.Terminated{
Terminate: true, Index: 1,
Query: "bc.*{,b,cd}",
},
Childs: []*TreeItemStr{
{
Node: "*", Childs: []*TreeItemStr{},
Terminated: "bc.*{,b,cd}*", TermIndex: 0, Term: true,
Terminated: items.Terminated{
Terminate: true, Index: 0,
Query: "bc.*{,b,cd}*",
},
},
},
},
Expand Down
17 changes: 14 additions & 3 deletions glob/tree_stringlist_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package glob

import (
"testing"

"github.com/msaf1980/go-matcher/pkg/items"
)

func TestGlobTree_StringList(t *testing.T) {
Expand All @@ -25,7 +27,10 @@ func TestGlobTree_StringList(t *testing.T) {
Node: "{b,cd}", Childs: []*TreeItemStr{
{
Node: "*", Childs: []*TreeItemStr{},
Terminated: "a.*.{b,cd}*.e", TermIndex: 0, Term: true,
Terminated: items.Terminated{
Terminate: true, Index: 0,
Query: "a.*.{b,cd}*.e",
},
},
},
},
Expand Down Expand Up @@ -65,7 +70,10 @@ func TestGlobTree_StringList(t *testing.T) {
Node: "{b,cd}", Childs: []*TreeItemStr{
{
Node: "*", Childs: []*TreeItemStr{},
Terminated: "*{b,cd}*.df", TermIndex: 0, Term: true,
Terminated: items.Terminated{
Terminate: true, Index: 0,
Query: "*{b,cd}*.df",
},
},
},
},
Expand Down Expand Up @@ -96,7 +104,10 @@ func TestGlobTree_StringList(t *testing.T) {
Node: ".", Childs: []*TreeItemStr{
{
Node: "{bc,c}", Childs: []*TreeItemStr{},
Terminated: "a.b*.{bc,c}", TermIndex: 0, Term: true,
Terminated: items.Terminated{
Terminate: true, Index: 0,
Query: "a.b*.{bc,c}",
},
},
},
},
Expand Down
10 changes: 3 additions & 7 deletions glob/tree_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,11 @@ import (
)

type TreeItemStr struct {
Node string `json:"node"`
Node string

Reverse bool `json:"reverse"` // for suffix
Reverse bool

Term bool `json:"term"`
Terminated string `json:"terminated"` // end of chain (resulting raw/normalized globs)
TermIndex int `json:"term_index"` // rule num of end of chain (resulting glob), can be used in specific cases
Terminated items.Terminated

// TODO: may be some ordered tree for complete string nodes search speedup (on large set) ?
Childs []*TreeItemStr `json:"childs"` // next possible parts slice
Expand All @@ -35,9 +33,7 @@ func StringTreeItem(treeItem *items.TreeItem) *TreeItemStr {
Node: node,
Reverse: treeItem.Reverse,
Childs: make([]*TreeItemStr, 0, len(treeItem.Childs)),
Term: treeItem.Terminate,
Terminated: treeItem.Terminated,
TermIndex: treeItem.TermIndex,
}

for _, child := range treeItem.Childs {
Expand Down
Loading

0 comments on commit 528eed3

Please sign in to comment.