-
Notifications
You must be signed in to change notification settings - Fork 115
Open
Description
Here are some of the slowest lines in my usage
https://github.com/derekparker/trie/blob/master/trie.go#L72
I am attempting to optimize these by short circuit logic and removing unneeded function calls.
ROUTINE ======================== github.com/derekparker/trie.(*Trie).Find in /home/mdupont/gocode/src/github.com/derekparker/trie/trie.go
240ms 1.93s (flat, cum) 36.90% of Total
. . 67:}
. . 68:
. . 69:// Finds and returns meta data associated
. . 70:// with `key`.
. . 71:func (t *Trie) Find(key string) (*Node, bool) {
90ms 450ms 72: node := findNode(t.Root(), []rune(key))
. . 73: if node == nil {
. . 74: return nil, false
. . 75: }
. . 76:
150ms 1.48s 77: node, ok := node.Children()[nul]
. . 78: if !ok || !node.term {
. . 79: return nil, false
. . 80: }
. . 81:
. . 82: return node, true
And the second one
ROUTINE ======================== github.com/derekparker/trie.findNode in /home/mdupont/gocode/src/github.com/derekparker/trie/trie.go
70ms 70ms (flat, cum) 1.34% of Total
. . 179:// mask of this node.
. . 180:func (n Node) Mask() uint64 {
. . 181: return n.mask
. . 182:}
. . 183:
Maby we could check if the node was nil before calling it.
https://github.com/derekparker/trie/blob/master/trie.go#L185
60ms 60ms 184:func findNode(node *Node, runes []rune) *Node {
. . 185: if node == nil {
. . 186: return nil
. . 187: }
. . 188:
10ms 10ms 189: if len(runes) == 0 {
. . 190: return node
. . 191: }
Metadata
Metadata
Assignees
Labels
No labels