Skip to contentSkip to conversation

checksum: fix unstable sort of checksums

PATCH In review [email protected] 2 participants 3 messages May 14, 2024

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 checksum: fix unstable sort of checksums

From: Yang Xu <[email protected]>

Using only the checksum as sorting key can lead to unstable results when same content files exist in different subfolders, affecting the taskhash calculation due to its sensitivity to the order of files in checksums.

This commit changes the sorting key to use both checksum and file path, ensuring stable sorting and enhancing sstate cache hit rates.

---
 lib/bb/checksum.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/bb/checksum.py +1 -1
index 557793d3..5294ddf1 100644
@@ -140,5 +140,5 @@ class FileChecksumCache(MultiProcessCache):
                 if checksum:
                     checksums.append((pth, checksum))
 
-        checksums.sort(key=operator.itemgetter(1))
+        checksums.sort(key=lambda x:(x[1], x[0]))
         return checksums
Signature · 1 line
2.25.1
#1 lore raw
Quoted 19 lines · Yang Xu via lists.openembedded.org

From: Yang Xu <[email protected]>

Using only the checksum as sorting key can lead to unstable results when same content files exist in different subfolders, affecting the taskhash calculation due to its sensitivity to the order of files in checksums.

This commit changes the sorting key to use both checksum and file path, ensuring stable sorting and enhancing sstate cache hit rates.

---
 lib/bb/checksum.py | 2 +-

 1 file changed, 1 insertion(+), 1 deletion(-)
lib/bb/checksum.py +0 -0
index 557793d3..5294ddf1 100644
@@ -140,5 +140,5 @@ class FileChecksumCache(MultiProcessCache):
Quoted 7 lines

                 if checksum:
                     checksums.append((pth, checksum))
-        checksums.sort(key=operator.itemgetter(1)) +        checksums.sort(key=lambda x:(x[1], x[0])) return checksums

Which version of the project are you testing this with?

The checksum data is sorted where it is used in siggen.py so sorting here shouldn't make much difference?

Cheers,

Richard

author
#2 lore raw

Dear Richard,

Sorry, I use a old version "kirkstone". Yes, I see the unstable sort problem is fixed in siggen.py in newer version. I think the existed solution is also OK.

Please ignore current patch.

Thank you