-
-
Notifications
You must be signed in to change notification settings - Fork 121
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
improve performance of join by make it internal #125
Conversation
This is just a question: does this version behave properly when given a stream as argument?
|
Good question, yes should work, internal functions does not know about generators, will only get values. But i'm not sure how it get compiled to make it work in these cases, now i got curious. So i guess a call to a function that has any argument that results in no outputs will itself result in no output? seems resonable and the only way it could be? :) Tried your examples with the change: $ go run cmd/gojq/main.go -nr '["a","b"] | join(",", "\n")'
a,b
a
b
$ go run cmd/gojq/main.go -nr '["a","b"] | join(empty)' |
@@ -1777,7 +1777,7 @@ | |||
- 'try join(",") catch .' | |||
input: '["1","2",[3,4,5]]' | |||
expected: | | |||
"cannot add: string (\"1,2,\") and array ([3,4,5])" | |||
"cannot join: array ([3,4,5])" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it makes sense to change the error if we do it this way or?
Maybe it's possible to have a more generic internal help function for improving performance of reduce + binop builtin functions? like keep map over array in jq and then pass result to a internal function with argument for how it should aggregate? |
You don't need to worry about stream as argument of internal functions because they are processed before called. |
c28742f
to
982b9b7
Compare
func.go
Outdated
} | ||
} | ||
return strings.Join(ss, sep) | ||
case map[string]interface{}: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The object case got a bit messy. It does the same thing as .[]
, each in sorted key order which is different from jq.
This growing complexity is the reason I stopped making it internal. I don't like the duplicates with the executor and pathValue to be used by internal functions. So how about |
982b9b7
to
f305e88
Compare
I agree, i've revised the implementation to your second suggestion. By avoid cloning the array do you mean implement our own version of |
Also i noticed that the benchmarks were all wrong, i accidentally used |
func.go
Outdated
|
||
if len(ss) == 1 { | ||
return ss[0] | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is to allow [1] | join(1)
, but would be nice to move this check earlier somehow
f305e88
to
69cb4b6
Compare
Updated to use own string builder, long when from 57242 to 48389 |
func.go
Outdated
sl += 5 | ||
} | ||
case int, float64, *big.Int: | ||
sl += 10 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
guessed length, should be better?
No, use |
69cb4b6
to
9dd780d
Compare
Ok switching back to |
9dd780d
to
9e3139b
Compare
Avoids exponential string append Before: BenchmarkJoinShort BenchmarkJoinShort-4 26947 44399 ns/op BenchmarkJoinLong BenchmarkJoinLong-4 145 7295904 ns/op After: BenchmarkJoinShort BenchmarkJoinShort-4 81789 14456 ns/op BenchmarkJoinLong BenchmarkJoinLong-4 22002 53791 ns/op
9e3139b
to
aaf5e38
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you.
👍 appreciate your comments and suggestions |
Avoids exponential string append
Before:
BenchmarkJoinShort
BenchmarkJoinShort-4 26947 44399 ns/op
BenchmarkJoinLong
BenchmarkJoinLong-4 145 7295904 ns/op
After:
BenchmarkJoinShort
BenchmarkJoinShort-4 81789 14456 ns/op
BenchmarkJoinLong
BenchmarkJoinLong-4 22002 53791 ns/op