Skip to content

Performance: limit number of database transactions #34

Description

@mattboehm

In an attempt to detect hotspots in the codebase, I ran a a sample program with smiley multiple times, with different parts of the smiley codebase commented out. (Using a LocalPublisher).

Run Time
Base 8.6s
Comment out insert line in db.trace() ~8.6s
Make all db.trace() calls use the same transaction 2.25s
Comment out transaction and insert in db.trace 1.3s

It appears that using fewer transactions might speed things up by a factor of 2-4. I suspect that even buffering inserts into groups of 5 would go a long way in improving performance. The downside to this approach is added code complexity and the chance that a failed insert causes one to roll back additional records (unless when you catch this, you rollback and apply those inserts in separate transactions.)

If this batching behavior is wanted, it could be implemented in a few ways:

  • Always batch
  • Batch if an argument is passed into LocalPublisher's constructor
  • Subclass LocalPublisher with a BatchingLocalPublisher (or FastLocalPublisher)

I'm happy to give this a shot, but wanted to float the idea out here first to see what others thought.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions