Skip to content
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

OGM batch performance problems due to string concatenation #261

Open
k-sok opened this issue Jan 8, 2018 · 2 comments
Open

OGM batch performance problems due to string concatenation #261

k-sok opened this issue Jan 8, 2018 · 2 comments

Comments

@k-sok
Copy link

k-sok commented Jan 8, 2018

The resulting batch script is built by using string concatenation.

commands = 'BEGIN\n'
commands += cmd1
commands += cmd2
...
commands += cmdN
g.client.batch(commands)

The larger the entire script is (i.e. the commands string) the longer takes each concatenation operation (because of the underlying memory reallocation and copying).

A better approach is to use a list of strings and join it when committing.

commands = ['BEGIN']
commands.append(cmd1)
commands.append(cmd2)
...
commands.append(cmdN)
g.client.batch('\n'.join(commands)

By implementing the above solution, I was able to improve the performance with large batches by magnitudes.

@TropicalPenguin
Copy link
Collaborator

TropicalPenguin commented Jan 8, 2018 via email

@k-sok
Copy link
Author

k-sok commented Jan 8, 2018

Yes, just saw it after forking. I wonder how are the chances that this stack design will survive to the next version. I have to subclass Batch and have to decide what to rely on...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants