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

perf: cache barcode scan result #32629

Merged
merged 3 commits into from Oct 20, 2022
Merged

Conversation

dj12djdjs
Copy link
Member

@dj12djdjs dj12djdjs commented Oct 17, 2022

  • Added cached barcode result up to 2 minuets to reduce latency between continues (same item) scans.

Locally this saves ~2-5ms per scan.
Remote server: Untested.

The time saving really isn't that much, but it's something.

@github-actions github-actions bot added needs-tests This PR needs automated unit-tests. stock labels Oct 17, 2022
@dj12djdjs dj12djdjs marked this pull request as draft October 17, 2022 21:37
@codecov
Copy link

codecov bot commented Oct 17, 2022

Codecov Report

Merging #32629 (72e89df) into develop (32117c0) will increase coverage by 0.04%.
The diff coverage is 88.23%.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop   #32629      +/-   ##
===========================================
+ Coverage    63.68%   63.72%   +0.04%     
===========================================
  Files          816      816              
  Lines        58260    58324      +64     
===========================================
+ Hits         37102    37169      +67     
+ Misses       21158    21155       -3     
Impacted Files Coverage Δ
erpnext/stock/utils.py 78.64% <88.23%> (+0.37%) ⬆️
...tch_item_expiry_status/batch_item_expiry_status.py 66.66% <0.00%> (-1.26%) ⬇️
.../report/delayed_item_report/delayed_item_report.py 60.00% <0.00%> (-0.79%) ⬇️
...wise_balance_history/batch_wise_balance_history.py 67.79% <0.00%> (-0.54%) ⬇️
erpnext/accounts/utils.py 73.30% <0.00%> (ø)
...xt/accounts/doctype/payment_entry/payment_entry.py 72.79% <0.00%> (ø)
...purchase_order_analysis/purchase_order_analysis.py 0.00% <0.00%> (ø)
...tation_comparison/supplier_quotation_comparison.py 0.00% <0.00%> (ø)
erpnext/manufacturing/doctype/job_card/job_card.py 71.32% <0.00%> (+0.23%) ⬆️
erpnext/accounts/doctype/pricing_rule/utils.py 74.05% <0.00%> (+0.38%) ⬆️
... and 8 more

@dj12djdjs dj12djdjs marked this pull request as ready for review October 18, 2022 19:08
@ankush
Copy link
Member

ankush commented Oct 19, 2022

The time saving really isn't that much, but it's something.

Is it anything? The columns are indexed so it's not like the DB query is slow. 😬

image

A typical scan request is completed within 3 milliseconds!

@ankush
Copy link
Member

ankush commented Oct 19, 2022

Benchmarked scan_barcode using get_value/set_value and redis only (no local caching):

  • Baseline: 1.2 ms
  • With this change: 0.03 ms 🥴

So it's something! Though I recon biggest time consumer here would be the latency itself, so the locality of the server matters more than anything. Can't beat speed of light 🚀

If it's for repeat scan of same items only then even better option would be limited client side caching.

erpnext/stock/utils.py Outdated Show resolved Hide resolved
Co-authored-by: Ankush Menat <ankushmenat@gmail.com>
@ankush ankush merged commit b88e850 into frappe:develop Oct 20, 2022
@ankush ankush added backport version-14-hotfix backport to version 14 and removed needs-tests This PR needs automated unit-tests. labels Oct 20, 2022
mergify bot pushed a commit that referenced this pull request Oct 20, 2022
* perf: cache barcode scan result

* feat: BarcodeScanResult type

* fix: use safe `get_value` `set_value`

Co-authored-by: Ankush Menat <ankushmenat@gmail.com>
(cherry picked from commit b88e850)
ankush pushed a commit that referenced this pull request Oct 20, 2022
perf: cache barcode scan result (#32629)

* perf: cache barcode scan result

* feat: BarcodeScanResult type

* fix: use safe `get_value` `set_value`

Co-authored-by: Ankush Menat <ankushmenat@gmail.com>
(cherry picked from commit b88e850)

Co-authored-by: Devin Slauenwhite <devin.slauenwhite@gmail.com>
frappe-pr-bot pushed a commit that referenced this pull request Oct 26, 2022
# [14.4.0](v14.3.1...v14.4.0) (2022-10-26)

### Bug Fixes

* Advance paid amount in orders (backport [#32642](#32642)) ([#32648](#32648)) ([8a88105](8a88105))
* allow to create Sales Order from expired Quotation ([#32641](#32641)) ([ccc58f4](ccc58f4))
* Billing Address for inter-company purchase docs ([f8934fa](f8934fa))
* BOM cost update message ([e539579](e539579))
* dont update item info twice ([8876904](8876904))
* incorrect qty in material request ([da538a3](da538a3))
* number of months subscription plan ([fff9e76](fff9e76))
* overlap error not raised for job card in case of workstation with production capacity ([ed2a093](ed2a093))
* party type and party mandatory on updating outstanding ([9a5e238](9a5e238))
* searchfield not working for cuctsomer, supplier as per customize form ([fb1c307](fb1c307))
* unset contact details ([d7a65b1](d7a65b1))

### Features

* Basic Payment Ledger report ([5cb9f7b](5cb9f7b))
* Repayment schedule types for term loans ([6ce32fd](6ce32fd))

### Performance Improvements

* cache barcode scan result (backport [#32629](#32629)) ([#32672](#32672)) ([3300856](3300856))
@barredterra barredterra mentioned this pull request Mar 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants