MCPcopy Create free account
hub / github.com/Snapchat/Valdi / loadModuleAsyncInner

Method loadModuleAsyncInner

valdi/src/valdi/runtime/Resources/ResourceManager.cpp:496–549  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

494 VALDI_WARN(_logger, "Invalid source map entry for {}", it.first);
495 continue;
496 }
497
498 auto fileKey = it.first.substring(expectedPrefix.length(), it.first.length() - expectedSuffix.length());
499
500 // Inject the source map content into the bundle
501 auto jsFile = bundle.getJs(fileKey);
502
503 if (jsFile) {
504 bundle.setJs(fileKey, JavaScriptFile(jsFile.value().content, it.second.toStringBox()));
505 }
506 }
507}
508
509void ResourceManager::preloadForComponentPath(const ComponentPath& componentPath) {
510 auto componentPathString = StringCache::getGlobal().makeString(componentPath.toString());
511 {
512 std::lock_guard<Mutex> lock(_seenComponentPathsMutex);
513 if (_seenComponentPaths.contains(componentPathString)) {
514 return;
515 }
516 _seenComponentPaths.insert(componentPathString);
517 }
518
519 // Attempt to perform some load operations while other operations are ongoing.
520 _workerQueue->async([self = strongSmallRef(this), componentPath = componentPath, componentPathString]() {
521 VALDI_TRACE_META("Valdi.preloadForComponentPath", componentPathString);
522 auto bundle = self->getBundle(componentPath.getResourceId().bundleName);
523 if (!bundle->hasModuleLoadStrategy()) {
524 return;
525 }
526
527 auto moduleLoadStrategy = bundle->getModuleLoadStrategy();
528 SC_ASSERT(moduleLoadStrategy.success(), moduleLoadStrategy.description());
529
530 if (!moduleLoadStrategy) {
531 return;
532 }
533 const auto* strategy = moduleLoadStrategy.value()->getStrategyForComponentPath(componentPathString);
534 if (strategy == nullptr) {
535 return;
536 }
537
538 // Load each modules
539 for (const auto& moduleName : strategy->valdiModules) {
540 self->getBundle(moduleName);
541 }
542 });
543}
544
545void ResourceManager::warmUpBundles(const std::vector<StringBox>& modulePaths) {
546 FlatSet<StringBox> seen;
547 std::vector<StringBox> bundles;
548 for (const auto& path : modulePaths) {
549 auto sv = path.toStringView();
550 auto slash = sv.find('/');
551 if (slash != std::string_view::npos) {
552 auto bundleName = StringCache::getGlobal().makeString(sv.substr(0, slash));

Callers 1

loadModuleAsyncMethod · 0.95

Calls 15

getGlobalFunction · 0.85
hasRemoteArchiveMethod · 0.80
getRegisteredManifestMethod · 0.80
makeStringMethod · 0.80
loadResourcesMethod · 0.80
endMethod · 0.65
insertMethod · 0.65
enterMethod · 0.65
loadModuleMethod · 0.65
valueMethod · 0.65
VoidClass · 0.50

Tested by

no test coverage detected