Skip to content

OGM batch performance problems due to string concatenation #261

@k-sok

Description

@k-sok

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions