Skip to content

Improve inventory costing reads and exclusion lookups - #11601

Draft
Chethan Thopaiah (ChethanT) wants to merge 4 commits into
mainfrom
private/chethant/AnalyzeCosting_Base
Draft

Chethan Thopaiah (ChethanT) wants to merge 4 commits into
mainfrom
private/chethant/AnalyzeCosting_Base

Conversation

@ChethanT

@ChethanT Chethan Thopaiah (ChethanT) commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

What & why

Measured, contained changes from an inventory cost-adjustment performance investigation:

  • Load manufacturing capacity cost FlowFields with SetAutoCalcFields and FindSet, rather than calculating them separately for each capacity entry.
  • Use dictionary-backed membership for open outbound and fixed-applied item-entry exclusions in W1 average-cost adjustment. Preserve their existing lifetime and handle duplicate fixed applications.
  • Aggregate ledger costs with CalcSums in W1 instead of transferring and summing every value entry in AL. Preserve the last record's non-total fields, the resulting key and filters, empty-scope behavior, temporary records, and the existing adjustment-buffer overlay.
  • Add three regression tests for capacity cost shares and SQL growth, including shared routing, subcontracting, negative cost corrections, additional reporting currency, and orders without capacity entries.
  • Add six ledger-cost regression tests covering actual/expected totals, ACY, corrections, record state, temporary records, empty scopes, and SQL budgets for small and large histories.
  • Make the accounting fixtures create their own required location/posting setup. Make coverage-test prerequisites explicit and compare equivalent per-item adjustment states, without weakening their assertions.

This draft does not implement the broader cache, transaction, scheduling, or parallel-processing proposals.

Scope is W1 only. Country-specific edits have been removed; propagation to country versions is deferred to MiApp at the end of the W1 work.

Customer assessment is out of scope at this stage and is not a prerequisite for continuing. Evaluate changes using source analysis and controlled synthetic workloads, keeping theoretical benefits separate from measured results.

Linked work

An approved issue/work-item link is still required before this draft is ready for review. No issue is claimed as fixed.

How I validated this

  • Author review and approval of the full diff before requesting review.
  • Built Base Application and Tests-SCM-Costing locally with static code analysis.
  • Published both apps and ran the tests against a fresh, isolated Business Central database.
  • Added correctness and SQL-growth regression tests.
  • Resolve the four baseline failures without changing production behavior or relaxing assertions.
  • Complete the local synthetic baseline and safety assessment.
  • At the end of the W1 work, use MiApp to propagate changes to country versions.

Controlled before/after comparison

Rebuilt the original and optimized W1 engines as successive package versions and verified the installed engine and test-app versions before each run. Ran the same 58 tests, using the same corrected fixtures, across:

  • Codeunit 133504, SCM Costing Performance.
  • Codeunit 137070, SCM Avg. Cost Calc.
  • Codeunit 137011, SCM Revaluation-II.
Engine Passed Failed
Original implementation 56 2
Optimized implementation 58 0

Only the two newly added performance-budget guards fail on the original engine: capacity SQL-statement growth and ledger SQL-row transfer. Both pass on the optimized engine. All accounting and existing coverage assertions pass on both engines.

Baseline prerequisites corrected

  • Manual-adjustment scenarios use a benchmark company with automatic adjustment set to Never; the two coverage tests also set this explicitly.
  • AvgPurchRevalSales now creates an in-transit location with posting setup rather than selecting an arbitrary demo location.
  • TestBug270797_UsingTransfer creates a destination location with posting setup and uses the same destination for the later sale.
  • VSTF268387 explicitly selects item-level costing so the generated SKUs are included. Its exact counts remain unchanged: two hits for one SKU and one additional hit per additional SKU.
  • The FIFO coverage comparison uses deterministic fixture inputs 3 and 12 so both measured final adjustments follow an earlier sale adjustment for that item. The original 20-percent tolerance and accounting checks are unchanged. A separate unrelated-item warm-up did not resolve the mismatch and was not retained.

Capacity measurement

The original calculation executes 31, 112, and 210 SQL statements for fixtures containing 10, 50, and 100 capacity entries. With batching, both larger fixtures use at most 10 more statements than the 10-entry fixture. Passing tests do not print absolute optimized counts.

Ledger measurement

Value entries Baseline session SQL rows Optimized session SQL rows Baseline statements Optimized statement bound
12 13 <=5 1 <=3
120 121 <=5 2 <=3
1,200 1,201 <=5 2 <=3

One- and two-entry histories also pass a separate guard of at most three rows and two SQL statements. Passing tests do not print the absolute optimized counters, so only these bounds are established.

SessionInformation.SqlRowsRead measures session SQL rows, not physical database logical reads. Read-only cached-plan inspection confirms the ledger aggregate uses a key lookup and UPDLOCK in the exercised workload: lower row transfer does not imply constant SQL work or shorter lock duration. Paired logical-read/elapsed-time measurements, memory measurements, and synthetic contention testing remain outstanding. Customer-scale latency assessment is deferred, not a blocker for continuing this work. Country propagation and validation will follow the W1 work.

Risk & compatibility

No schema, public interface, transaction boundary, G/L posting, or scheduling changes. Existing manufacturing subscriber hooks and the ledger calculation's handled override remain in place. Persistent ledger totals still receive the temporary adjustment-buffer costs through the existing callers.

FindLast preserves the public record-state contract before aggregation, but can add one SQL round trip for tiny histories. No SIFT/index addition or customer-scale end-to-end speedup is claimed.

Dictionary membership trades additional per-entry bookkeeping for hash-based membership lookups; large-workload memory impact still needs measurement. This remains a draft while the broader accounting and performance gates are incomplete.

Add capacity cost-share and SQL-growth regression coverage.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions github-actions Bot added the Team: SCM GitHub request for SCM area label Sep 18, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Could not find a linked work item. Please link one in either of these ways: (1) link an ADO work item using the pattern 'AB#' followed by the work item number - you may use the 'Fixes' keyword to automatically resolve it when the pull request is merged, e.g. 'Fixes AB#1234'; or (2) link a GitHub issue of type 'Task' using the pattern 'Fixes #' followed by the issue number, e.g. 'Fixes #1234'.

Preserve ledger record state and temporary buffers while bounding SQL row transfer. Add six costing regression tests and propagate dictionary membership to APAC and RU.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@ChethanT Chethan Thopaiah (ChethanT) changed the title Improve capacity costing reads and average-cost exclusion lookups Improve inventory costing reads and exclusion lookups Sep 18, 2026
Remove manual APAC and RU edits. Defer country propagation to MiApp after the W1 work is complete.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
… state

Create required transfer posting setup, explicitly configure SKU coverage prerequisites, and compare equivalent per-item FIFO adjustment states without changing assertions.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Team: SCM GitHub request for SCM area

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant