In this post, I want to describe how to turbocharge Virto Commerce performance and efficiency! With the integration of the entityframework-extensions.net library, we have unlocked a powerful feature that will significantly enhance your data storage and retrieval processes, resulting in faster and more streamlined operations.
How It Works
The entityframework-extensions.net library brings high-performance batch and bulk operations. With BulkSave, you can process multiple entities in a single transaction, rather than performing individual operations, significantly reducing the overhead associated with storing and retrieving data.
The Power of BulkSave
By using BulkSave, we’ve witnessed substantial performance improvements across various operations within the platform, primary for Cart and Order operations.
Implementation Details
To integrate the entityframework-extensions.net library, you will need to create a new vc module and configure the library to enable this feature. Additionally, you need to create DbContextWithBulkSaveChangesUnitOfWork class, extending the DbContextUnitOfWork to leverage the BulkSave capabilities.
public class DbContextWithBulkSaveChangesUnitOfWork : DbContextUnitOfWork
{
public DbContextWithBulkSaveChangesUnitOfWork(DbContext context) : base(context)
{
}
public async override Task<int> CommitAsync()
{
await base.DbContext.BulkSaveChangesAsync();
return 1;
}
public override int Commit()
{
base.DbContext.BulkSaveChanges();
return 1;
}
}
And override DbContextUnitOfWork type with DbContextWithBulkSaveChangesUnitOfWork in Module.Initialize method. That’s all folks.
public class Module: IModule, IHasConfiguration
{
...
public void Initialize(IServiceCollection serviceCollection)
{
// Override models
AbstractTypeFactory<DbContextUnitOfWork>.OverrideType<DbContextUnitOfWork, DbContextWithBulkSaveChangesUnitOfWork>();
}
...
}
Test Results
To illustrate the impressive impact of the entityframework-extensions.net integration, we conducted tests to compare operations with and without BulkSave, we use a small instance in Virto Cloud, up to 20 products in the cart and 100 users simultaneously. The results were remarkable, showcasing substantial time reductions for various actions:
XAPI Operation | Native, ms | Using extensions, ms | Diff, ms |
---|---|---|---|
Add To Cart | 810 | 656 | -154 |
Merge Cart | 1178 | 783 | -395 |
Add Payment | 781 | 676 | -105 |
Update Payment | 816 | 719 | -97 |
Create Order | 1017 | 790 | -227 |
Embrace the Power of entityframework-extensions.net
With the implementation of the entityframework-extensions.net library, the Virto Commerce Platform has taken a giant leap forward in performance optimization. We are confident that you will appreciate the enhanced speed and efficiency it brings to your e-commerce operations.
Note
Please be aware that the entityframework-extensions.net library is a paid feature. However, the immense benefits it delivers are well worth the investment, especially if you prioritize seamless user experiences and top-notch performance.