-
Notifications
You must be signed in to change notification settings - Fork 227
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
Increase performance #408
Comments
Hey, interesting and nice to see your working on postgres decoders! I wonder if the pgheap decoder produces structs with lots of fields? can i get the test file "16397_8" somewhere? Also could you try with the patch below? it will use a bit more memory but should speed up that check. I've thought adding something like this to speed up key indexing from jq anyway but haven't bothered as none of the current decoders produce structs with lots of fields. diff --git a/pkg/decode/decode.go b/pkg/decode/decode.go
index e899eac3..5ddc834f 100644
--- a/pkg/decode/decode.go
+++ b/pkg/decode/decode.go
@@ -721,11 +721,10 @@ func (d *D) AddChild(v *Value) {
switch fv := d.Value.V.(type) {
case *Compound:
if !fv.IsArray {
- for _, ff := range fv.Children {
- if ff.Name == v.Name {
- d.Fatalf("%q already exist in struct %s", v.Name, d.Value.Name)
- }
+ if _, ok := fv.Keys[v.Name]; ok {
+ d.Fatalf("%q already exist in struct %s", v.Name, d.Value.Name)
}
+ fv.Keys[v.Name] = struct{}{}
}
fv.Children = append(fv.Children, v)
}
diff --git a/pkg/decode/value.go b/pkg/decode/value.go
index 63927f6a..bf82ba04 100644
--- a/pkg/decode/value.go
+++ b/pkg/decode/value.go
@@ -13,6 +13,7 @@ type Compound struct {
IsArray bool
RangeSorted bool
Children []*Value
+ Keys map[string]struct{}
Description string
} Alternatively we could make that check optional somehow in compile time or runtime as it is quite nice to have it during decoder development. |
Link to 16397_8: 16397_8 - first 8 mb of 1 GB 16397 |
Thank you for patch. |
Patch works well: time fq -d pgheap -o flavour=postgres14 ".Pages[0].PageHeaderData.pd_linp[0,-1] | tovalue" 16397_8 { "lp_flags": "LP_NORMAL", "lp_len": 121, "lp_off": 8064 } { "lp_flags": "LP_NORMAL", "lp_len": 121, "lp_off": 384 } real 0m2.227s user 0m3.679s sys 0m0.264s |
Pull request with map: |
Fixed by #411 |
BTW feel free to open a PR for the postgres decoder. Had a quick look at your branch and it looks impressive 👍 I think it is usually good to do to a PR earlier to get feedback and start iterating. Also i usually prefer rebase over merging upstream would that be ok with you? personally think it keeps the history clearer and easier to follow |
What version are you using (
fq -v
)?How was fq installed?
My branch:
https://github.com/pnsafonov/fq/tree/postgres
Can you reproduce the problem using the latest release or master branch?
Yes
What did you do?
I am implementing PostgreSQL format parsers. I can offer perfomance fix.
Then i made fix, and run again:
This fix decrease execution time 1m20.079s -> 0m2.076s, file
decode.go
:Also i made some perf with go tools. This was how i found fix:
The text was updated successfully, but these errors were encountered: