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: Stop old batch loading #3679

Merged

Conversation

Strepto
Copy link
Contributor

@Strepto Strepto commented Sep 6, 2023

Type of change

Feat

Jira ticket 📘

https://cognitedata.atlassian.net/browse/

Description 📝

I think this is a simple fix that will potentially reduce waste in loading and then discarding sectors. I have not extensively tested this, but it seems like a easy win for improved loading performance.

I know this fix is not as important with remote models as the warning Abort signal is not supported for local models appears in the log and I presume this would have cancelled something.

How has this been tested? 🔍

Tested with local model in chrome using dev-tools to throttle network latency to 200ms. Also tested with remote Equinor-models, with improvements when the network or device is slow. Combined with #3674 I believe this is a big difference in performance.

Lots of more possible improvements (should cancel the ongoing batch for instance) but this is a oneliner, so hard to beat.

Test instructions ℹ️

I suggest playing around with the code to see the impact

for example this debug code is good to show the loading of old sectors still active way later.


    for (const batch of chunk(changedSectors, SectorLoadingBatchSize)) {
      if (currentBatchId !== this._batchId) {
        console.log('Stopped loading old batch ', currentBatchId, this._batchId);
        // Uncomment the break to see the current behavior
        break; // Stop processing this batch as a new batch has started, and will discard results from old batches.
      }

      const filteredSectors = await this.filterSectors(sectorCullerInput, batch, sectorCuller, progressHelper);
      const consumedPromises = this.startLoadingBatch(filteredSectors, cadModels);
      for await (const consumed of PromiseUtils.raceUntilAllCompleted(consumedPromises)) {
        const resolvedSector = consumed.result;
        if (currentBatchId === this._batchId) {
          if (resolvedSector !== undefined) {
            this._modelStateHandler.updateState(
              resolvedSector.modelIdentifier,
              resolvedSector.metadata.id,
              resolvedSector.levelOfDetail
            );
            yield resolvedSector;
          }
        } else {
          console.log('Discarded sector due to old batch', currentBatchId, this._batchId);
        }
        progressHelper.reportNewSectorsLoaded(1);
      }
    }
  }

Checklist ☑️

  • I am proud of this feature.
  • I have performed a self-review of my own code.
  • I have added PR type (Feat, Bug, Chore, Test, Docs, Style, Refactor) to the PR title.
  • I have manually tested this for different scenarios (different models, formats, devices, browsers).
  • I have commented my code in hard-to-understand areas.
  • I have made corresponding changes to the public documentation.
  • I have added unit and visuals tests to prove that my feature works to the best of my ability.
  • I have refactored the code for readability to the best of my ability.
  • I have checked that my changes do not introduce regressions in the public documentation.
  • I have outlined any known defects / lacking capabilities in the contents of this PR.
  • I have listed any remaining work that should follow this PR in the description or jira/miro/etc.
  • I have added TSDoc to any public facing changes.
  • I have added "developer documentation" in any package README.md that is related / applicable to this PR.
  • I have noted down and am currently tracking any technical debt introduced in this PR.
  • I have thoroughly thought about the architecture of this implementation.
  • I have asked peers to test this feature.

@codecov
Copy link

codecov bot commented Sep 6, 2023

Codecov Report

Merging #3679 (0badfac) into master (49ae9d5) will decrease coverage by 0.02%.
The diff coverage is 25.00%.

@@            Coverage Diff             @@
##           master    #3679      +/-   ##
==========================================
- Coverage   71.70%   71.68%   -0.02%     
==========================================
  Files         346      346              
  Lines       33739    33743       +4     
  Branches     2650     2649       -1     
==========================================
- Hits        24192    24190       -2     
- Misses       9440     9445       +5     
- Partials      107      108       +1     
Files Changed Coverage Δ
...etry-loaders/src/sector/SectorDownloadScheduler.ts 95.28% <0.00%> (-2.06%) ⬇️
...es/cad-geometry-loaders/src/sector/SectorLoader.ts 97.84% <100.00%> (+0.01%) ⬆️

... and 1 file with indirect coverage changes

@Strepto Strepto marked this pull request as ready for review September 13, 2023 07:18
@Strepto Strepto requested a review from a team as a code owner September 13, 2023 07:18
@Strepto Strepto changed the title feature: Stop old batch loading feat: Stop old batch loading Sep 13, 2023
@christjt christjt enabled auto-merge (squash) September 20, 2023 10:43
@christjt christjt merged commit 7b8c9b0 into cognitedata:master Sep 20, 2023
14 checks passed
@Strepto Strepto deleted the nih/feature/sectorloading-batching branch September 20, 2023 10:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants