-
Notifications
You must be signed in to change notification settings - Fork 25
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
Optimize arguments handling #127
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,13 +32,16 @@ func ParseStatement(sql string) ([]string, []ParamsInfo, error) { | |
} | ||
|
||
func ParseStatementAndArgs(sql string, args []driver.NamedValue) ([]string, []Params, error) { | ||
stmts, _ := sqliteparserutils.SplitStatement(sql) | ||
|
||
if len(args) == 0 { | ||
return stmts, nil, nil | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we return array for params here too: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I thought about it but this is proportional to the size of the input which is bad. For example for 100k or 1M statements that's not great especially that this is continuous memory which is hard to find in a fragmented heap. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For 1M statements this array will occupy at most 32MB. But from what I saw locally - dump process consumes GBs of RAM to handle 1M statements or so... So, I agree that this is not great, but I doubt if this is actually that critical... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Streaming is my next step. Just fixing stuff on the way. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree to some extend but this is not only about memory. Without special casing the arguments handling code will execute on those empty arrays and it does some logic including conditions. I don't want to execute this for 1M statements when I don't have to. |
||
} | ||
parameters, err := ConvertArgs(args) | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
|
||
stmts, _ := sqliteparserutils.SplitStatement(sql) | ||
|
||
stmtsParams := make([]Params, len(stmts)) | ||
totalParametersAlreadyUsed := 0 | ||
for idx, stmt := range stmts { | ||
|
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.
Can we add guard in the
AddArgs
method... } else if len(params.Positional()) > 0 { ...
and not change argument to pointer then?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.
but then we're not really removing special cases and we're doing additional check for 1M statements potentially.