@@ -622,11 +622,11 @@ actor class Main() = this {
622622
623623 let SAMPLE_SIZE : Nat = 10_000 ;
624624
625- // Serializes a random sample of up to SAMPLE_SIZE entries and extrapolates
626- // the total byte count, keeping to_candid allocations bounded.
625+ // Samples up to SAMPLE_SIZE entries and extrapolates the total byte count,
626+ // keeping to_candid allocations bounded regardless of map size .
627627 func sampleMapBytes< K , V > (
628628 map : TrieMap . TrieMap < K , V > ,
629- serialize : (K , V ) -> Blob ,
629+ entryBytes : (K , V ) -> Nat ,
630630 ) : Nat {
631631 let total = map. size();
632632 if (total == 0 ) return 0 ;
@@ -636,7 +636,7 @@ actor class Main() = this {
636636 var sampled = 0 ;
637637 for ((k, v) in map. entries()) {
638638 if (i % stride == 0 ) {
639- sum += serialize (k, v) . size( );
639+ sum += entryBytes (k, v);
640640 sampled += 1 ;
641641 };
642642 i += 1 ;
@@ -657,55 +657,55 @@ actor class Main() = this {
657657
658658 packageVersions = {
659659 count = packageVersions. size();
660- bytes = sampleMapBytes(packageVersions, func (k : PackageName , v : [PackageVersion ]) : Blob = to_candid ((k, v)) );
660+ bytes = sampleMapBytes(packageVersions, func (k : PackageName , v : [PackageVersion ]) : Nat { ( to_candid (k) : Blob ) . size() + ( to_candid (v) : Blob ) . size() } );
661661 };
662662 packageConfigs = {
663663 count = packageConfigs. size();
664- bytes = sampleMapBytes(packageConfigs, func (k : PackageId , v : PackageConfigV3 ) : Blob = to_candid ((k, v)) );
664+ bytes = sampleMapBytes(packageConfigs, func (k : PackageId , v : PackageConfigV3 ) : Nat { ( to_candid (k) : Blob ) . size() + ( to_candid (v) : Blob ) . size() } );
665665 };
666666 highestConfigs = {
667667 count = highestConfigs. size();
668- bytes = sampleMapBytes(highestConfigs, func (k : PackageName , v : PackageConfigV3 ) : Blob = to_candid ((k, v)) );
668+ bytes = sampleMapBytes(highestConfigs, func (k : PackageName , v : PackageConfigV3 ) : Nat { ( to_candid (k) : Blob ) . size() + ( to_candid (v) : Blob ) . size() } );
669669 };
670670 packagePublications = {
671671 count = packagePublications. size();
672- bytes = sampleMapBytes(packagePublications, func (k : PackageId , v : PackagePublication ) : Blob = to_candid ((k, v)) );
672+ bytes = sampleMapBytes(packagePublications, func (k : PackageId , v : PackagePublication ) : Nat { ( to_candid (k) : Blob ) . size() + ( to_candid (v) : Blob ) . size() } );
673673 };
674674 ownersByPackage = {
675675 count = ownersByPackage. size();
676- bytes = sampleMapBytes(ownersByPackage, func (k : PackageName , v : [Principal ]) : Blob = to_candid ((k, v)) );
676+ bytes = sampleMapBytes(ownersByPackage, func (k : PackageName , v : [Principal ]) : Nat { ( to_candid (k) : Blob ) . size() + ( to_candid (v) : Blob ) . size() } );
677677 };
678678 maintainersByPackage = {
679679 count = maintainersByPackage. size();
680- bytes = sampleMapBytes(maintainersByPackage, func (k : PackageName , v : [Principal ]) : Blob = to_candid ((k, v)) );
680+ bytes = sampleMapBytes(maintainersByPackage, func (k : PackageName , v : [Principal ]) : Nat { ( to_candid (k) : Blob ) . size() + ( to_candid (v) : Blob ) . size() } );
681681 };
682682 fileIdsByPackage = {
683683 count = fileIdsByPackage. size();
684- bytes = sampleMapBytes(fileIdsByPackage, func (k : PackageId , v : [FileId ]) : Blob = to_candid ((k, v)) );
684+ bytes = sampleMapBytes(fileIdsByPackage, func (k : PackageId , v : [FileId ]) : Nat { ( to_candid (k) : Blob ) . size() + ( to_candid (v) : Blob ) . size() } );
685685 };
686686 hashByFileId = {
687687 count = hashByFileId. size();
688- bytes = sampleMapBytes(hashByFileId, func (k : FileId , v : Blob ) : Blob = to_candid ((k, v)) );
688+ bytes = sampleMapBytes(hashByFileId, func (k : FileId , v : Blob ) : Nat { ( to_candid (k) : Blob ) . size() + ( to_candid (v) : Blob ) . size() } );
689689 };
690690 packageFileStats = {
691691 count = packageFileStats. size();
692- bytes = sampleMapBytes(packageFileStats, func (k : PackageId , v : PackageFileStats ) : Blob = to_candid ((k, v)) );
692+ bytes = sampleMapBytes(packageFileStats, func (k : PackageId , v : PackageFileStats ) : Nat { ( to_candid (k) : Blob ) . size() + ( to_candid (v) : Blob ) . size() } );
693693 };
694694 packageTestStats = {
695695 count = packageTestStats. size();
696- bytes = sampleMapBytes(packageTestStats, func (k : PackageId , v : TestStats ) : Blob = to_candid ((k, v)) );
696+ bytes = sampleMapBytes(packageTestStats, func (k : PackageId , v : TestStats ) : Nat { ( to_candid (k) : Blob ) . size() + ( to_candid (v) : Blob ) . size() } );
697697 };
698698 packageBenchmarks = {
699699 count = packageBenchmarks. size();
700- bytes = sampleMapBytes(packageBenchmarks, func (k : PackageId , v : Benchmarks ) : Blob = to_candid ((k, v)) );
700+ bytes = sampleMapBytes(packageBenchmarks, func (k : PackageId , v : Benchmarks ) : Nat { ( to_candid (k) : Blob ) . size() + ( to_candid (v) : Blob ) . size() } );
701701 };
702702 packageNotes = {
703703 count = packageNotes. size();
704- bytes = sampleMapBytes(packageNotes, func (k : PackageId , v : Text ) : Blob = to_candid ((k, v)) );
704+ bytes = sampleMapBytes(packageNotes, func (k : PackageId , v : Text ) : Nat { ( to_candid (k) : Blob ) . size() + ( to_candid (v) : Blob ) . size() } );
705705 };
706706 packageDocsCoverage = {
707707 count = packageDocsCoverage. size();
708- bytes = sampleMapBytes(packageDocsCoverage, func (k : PackageId , v : Float ) : Blob = to_candid ((k, v)) );
708+ bytes = sampleMapBytes(packageDocsCoverage, func (k : PackageId , v : Float ) : Nat { ( to_candid (k) : Blob ) . size() + ( to_candid (v) : Blob ) . size() } );
709709 };
710710
711711 downloadsByPackageName = dlStats. downloadsByPackageName;
0 commit comments