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

feat(medusa): Performance improvements of Carts domain #2648

Merged
merged 32 commits into from
Dec 7, 2022

Conversation

adrien2p
Copy link
Member

@adrien2p adrien2p commented Nov 22, 2022

What

I have created a new method on the cart service which is addLineItems, allowing a user to add one or multiple items in an optimized way. Also updated the generate method from the line item service which now also accept a object data or a collection of data which. Various places have been optimized and cache support has been added to the price selection strategy.

The overall optimization allows to reach another 9000% improvement in the response time as a median (Creating a cart with 6 items):

Min (ms) Median (ms) Max (ms) Median Improvement (%)
Before optimisation 1200 9999 12698 N/A
After optimisation 63 252 500 39x
After re optimisation 56 82 399 121x
After including addressed feedback 65 202 495 49x

FIXES CORE-722

@changeset-bot
Copy link

changeset-bot bot commented Nov 22, 2022

🦋 Changeset detected

Latest commit: 17c90c4

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@medusajs/medusa Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@adrien2p
Copy link
Member Author

adrien2p commented Nov 22, 2022

Creating a cart with 6 items. Usually a user would create a cart and then call the create line item each time a customer add an item. But in cases where the cart is created with some items here are the results.

Before refactoring (single instance and process):
Screenshot 2022-11-22 at 11 53 12

After refactoring (single instance and process):
Screenshot 2022-11-22 at 11 52 21

@adrien2p adrien2p force-pushed the feat/create-cart-perf-improvement branch from eb8ff59 to 0d84397 Compare November 22, 2022 15:50
@adrien2p
Copy link
Member Author

Last result with the same env

Screenshot 2022-11-23 at 09 35 26

@olivermrbl olivermrbl mentioned this pull request Nov 23, 2022
@adrien2p adrien2p force-pushed the feat/create-cart-perf-improvement branch 2 times, most recently from f7e7338 to 6f0137a Compare November 23, 2022 10:29
@adrien2p
Copy link
Member Author

adrien2p commented Nov 23, 2022

After re optimization, especially the generate method from the line item service which can now manage to generate a batch of line items

Screenshot 2022-11-23 at 13 45 54

@adrien2p adrien2p force-pushed the feat/create-cart-perf-improvement branch 3 times, most recently from c4a65ff to 5656f43 Compare November 23, 2022 16:25
@adrien2p adrien2p marked this pull request as ready for review November 23, 2022 16:40
@adrien2p adrien2p requested a review from a team as a code owner November 23, 2022 16:40
packages/medusa/src/interfaces/price-selection-strategy.ts Outdated Show resolved Hide resolved
packages/medusa/src/types/line-item.ts Outdated Show resolved Hide resolved
packages/medusa/src/types/line-item.ts Outdated Show resolved Hide resolved
packages/medusa/src/services/cache.ts Show resolved Hide resolved
packages/medusa/src/services/index.ts Show resolved Hide resolved
@adrien2p
Copy link
Member Author

Screenshot 2022-11-24 at 12 45 59

@adrien2p adrien2p force-pushed the feat/create-cart-perf-improvement branch from 426d8c6 to 9062b8e Compare December 7, 2022 08:53
@olivermrbl olivermrbl changed the title Feat/create cart perf improvement feat(medusa): Performance improvements of Carts domain Dec 7, 2022
Copy link
Contributor

@olivermrbl olivermrbl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 💪

@adrien2p adrien2p force-pushed the feat/create-cart-perf-improvement branch from a00fe15 to be706df Compare December 7, 2022 09:36
@adrien2p adrien2p closed this Dec 7, 2022
@adrien2p adrien2p reopened this Dec 7, 2022
@adrien2p
Copy link
Member Author

adrien2p commented Dec 7, 2022

I ve closed and reopened the pr to trigger the pipeline to run again

@kodiakhq kodiakhq bot merged commit 42d9c72 into develop Dec 7, 2022
@kodiakhq kodiakhq bot deleted the feat/create-cart-perf-improvement branch December 7, 2022 14:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants