<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugzilla.yoctoproject.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.6"
          urlbase="https://bugzilla.yoctoproject.org/"
          
          maintainer="it-coreprojects-helpdesk@linuxfoundation.org"
>

    <bug>
          <bug_id>13824</bug_id>
          
          <creation_ts>2020-03-05 02:04:03 +0000</creation_ts>
          <short_desc>slow loading cache</short_desc>
          <delta_ts>2020-04-26 06:02:05 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>7</classification_id>
          <classification>Build System, Metadata &amp; Runtime</classification>
          <product>BitBake</product>
          <component>bitbake</component>
          <version>unspecified</version>
          <rep_platform>x86</rep_platform>
          <op_sys>Multiple</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>Medium+</priority>
          <bug_severity>normal</bug_severity>
          <target_milestone>3.2 M1</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="yifan">153340508</reporter>
          <assigned_to name="Richard Purdie">richard.purdie</assigned_to>
          <cc>akuster</cc>
    
    <cc>poky.bs.watcher</cc>
    
    <cc>poky.watcher</cc>
          
          
          <cf_os>---</cf_os>
          <cf_regression_type>---</cf_regression_type>
          
          <cf_docchange>Don&apos;t know</cf_docchange>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>86661</commentid>
    <comment_count>0</comment_count>
    <who name="yifan">153340508</who>
    <bug_when>2020-03-05 02:04:03 +0000</bug_when>
    <thetext>In our project,we have over 4000 patches and 300hundred bb&apos;s. Then loading cache in incremental build is very slow.
I figured out that it is due to a problem algorithm in cache.py
And i have give out a improvement.
diff --git a/poky-sumo-19.0.1/bitbake/lib/bb/cache.py b/poky-sumo-19.0.1/bitbake/lib/bb/cache.py
old mode 100644
new mode 100755
index 168a77ac0..753d074f7
--- a/poky-sumo-19.0.1/bitbake/lib/bb/cache.py
+++ b/poky-sumo-19.0.1/bitbake/lib/bb/cache.py
@@ -610,31 +610,38 @@ class Cache(NoCache):
                                     fn, f)
                     self.remove(fn)
                     return False
-
+        import re
         if hasattr(info_array[0], &apos;file_checksums&apos;):
             for _, fl in info_array[0].file_checksums.items():
                 fl = fl.strip()
-                while fl:
-                    # A .split() would be simpler but means spaces or colons in filenames would break
-                    a = fl.find(&quot;:True&quot;)
-                    b = fl.find(&quot;:False&quot;)
-                    if ((a &lt; 0) and b) or ((b &gt; 0) and (b &lt; a)):
-                        f = fl[:b+6]
-                        fl = fl[b+7:]
-                    elif ((b &lt; 0) and a) or ((a &gt; 0) and (a &lt; b)):
-                        f = fl[:a+5]
-                        fl = fl[a+6:]
-                    else:
-                        break
-                    fl = fl.strip()
-                    if &quot;*&quot; in f:
-                        continue
-                    f, exist = f.split(&quot;:&quot;)
-                    if (exist == &quot;True&quot; and not os.path.exists(f)) or (exist == &quot;False&quot; and os.path.exists(f)):
-                        logger.debug(2, &quot;Cache: %s&apos;s file checksum list file %s changed&quot;,
-                                        fn, f)
+                flist=re.split(r&apos;(:True|:False)&apos;,fl)
+                for i in range(len(flist)):
+                    if ( &quot;:True&quot; == flist[i].strip() and not os.path.exists(flist[i-1].strip())) or ( &quot;:False&quot; == flist[i].strip() and  os.path.exists(flist[i-1].strip())):
+                        logger.error(2, &quot;Cache: %s&apos;s file checksum list file %s changed&quot;,
+                                        fn, flist[i-1])
                         self.remove(fn)
                         return False
+                #while fl:
+                    # A .split() would be simpler but means spaces or colons in filenames would break
+                    #a = fl.find(&quot;:True&quot;)
+                    #b = fl.find(&quot;:False&quot;)
+                    #if ((a &lt; 0) and b) or ((b &gt; 0) and (b &lt; a)):
+                        #f = fl[:b+6]
+                        #fl = fl[b+7:]
+                    #elif ((b &lt; 0) and a) or ((a &gt; 0) and (a &lt; b)):
+                        #f = fl[:a+5]
+                        #fl = fl[a+6:]
+                    #else:
+                        #break
+                    #fl = fl.strip()
+                    #if &quot;*&quot; in f:
+                        #continue
+                    #f, exist = f.split(&quot;:&quot;)
+                    #if (exist == &quot;True&quot; and not os.path.exists(f)) or (exist == &quot;False&quot; and os.path.exists(f)):
+                        #logger.debug(2, &quot;Cache: %s&apos;s file checksum list file %s changed&quot;,
+                                        #fn, f)
+                        #self.remove(fn)
+                        #return False

         if appends != info_array[0].appends:
             logger.debug(2, &quot;Cache: appends for %s changed&quot;, fn)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>86662</commentid>
    <comment_count>1</comment_count>
    <who name="Richard Purdie">richard.purdie</who>
    <bug_when>2020-03-05 13:16:05 +0000</bug_when>
    <thetext>Hi, 

Thanks for this. Could you describe a little bit more what the problem is and how this change fixes it please?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>86663</commentid>
    <comment_count>2</comment_count>
    <who name="yifan">153340508</who>
    <bug_when>2020-03-05 13:23:20 +0000</bug_when>
    <thetext>(In reply to comment #1)
&gt; Hi, 
&gt; 
&gt; Thanks for this. Could you describe a little bit more what the problem is
&gt; and how this change fixes it please?

Hello Richard, thanks for replying me.
The old method continually cut the &quot;fl&quot; string, while in python, this cut method takes O(n) time complexity,so in worst case ,it would take O(N^2) in total for loading cache process. In my compoany, we have over 4000 patches and in increamental build, &quot;loading cache&quot; takes about 3 min in my 32U128G machine. while the new method takes about 15seconds.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>86664</commentid>
    <comment_count>3</comment_count>
    <who name="yifan">153340508</who>
    <bug_when>2020-03-05 13:25:18 +0000</bug_when>
    <thetext>(In reply to comment #1)
&gt; Hi, 
&gt; 
&gt; Thanks for this. Could you describe a little bit more what the problem is
&gt; and how this change fixes it please?

It happens in in incremental build when the termianl shows &quot;loading cache ,loaded XXX entries form cache&quot;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>86673</commentid>
    <comment_count>4</comment_count>
    <who name="yifan">153340508</who>
    <bug_when>2020-03-06 01:04:53 +0000</bug_when>
    <thetext>(In reply to comment #2)
&gt; (In reply to comment #1)
&gt; &gt; Hi, 
&gt; &gt; 
&gt; &gt; Thanks for this. Could you describe a little bit more what the problem is
&gt; &gt; and how this change fixes it please?
&gt; 
&gt; Hello Richard, thanks for replying me.
&gt; The old method continually cut the &quot;fl&quot; string, while in python, this cut
&gt; method takes O(n) time complexity,so in worst case ,it would take O(N^2) in
&gt; total for loading cache process. In my compoany, we have over 4000 patches
&gt; and in increamental build, &quot;loading cache&quot; takes about 3 min in my 32U128G
&gt; machine. while the new method takes about 15seconds.

this change fixes old algorithm from time complexity from O(n^2) to O(n). the improvemtnt is extremely big especially in big project. Kernel patches usually has a number of over 1000. So doing loading cache would save a lot of time</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>86678</commentid>
    <comment_count>5</comment_count>
    <who name="Richard Purdie">richard.purdie</who>
    <bug_when>2020-03-06 22:04:02 +0000</bug_when>
    <thetext>Thanks for explaining, that helps and I can see the issue.

I am a little concerned the case handing &quot;*&quot; is lost, I&apos;m therefore worried there may be some corner cases which aren&apos;t handled correctly. We should also remove the commented code rather than just commenting it out.

I appreciate you&apos;re constrained upon how you can share patches, do you want to fix up the patch here with a commit message and signed-off-by or does someone else need to do that. I am grateful you have reported the problem as it does sound like a good fix!</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>86687</commentid>
    <comment_count>6</comment_count>
    <who name="yifan">153340508</who>
    <bug_when>2020-03-09 07:54:11 +0000</bug_when>
    <thetext>(In reply to comment #5)
&gt; Thanks for explaining, that helps and I can see the issue.
&gt; 
&gt; I am a little concerned the case handing &quot;*&quot; is lost, I&apos;m therefore worried
&gt; there may be some corner cases which aren&apos;t handled correctly. We should
&gt; also remove the commented code rather than just commenting it out.
&gt; 
&gt; I appreciate you&apos;re constrained upon how you can share patches, do you want
&gt; to fix up the patch here with a commit message and signed-off-by or does
&gt; someone else need to do that. I am grateful you have reported the problem as
&gt; it does sound like a good fix!

Hello,I have commit this fix.
https://git.yoctoproject.org/cgit/cgit.cgi/poky-contrib/commit/?h=happystudy-contrib/master&amp;id=8c9e646c0f5ecc7d239f518e2e6ef3be2f312dbe
In re module,  i have difined the split symbol as True and False, so if there are &quot;*&quot; or blank or other strange characoter in filename,it won&apos;t be splited. So this method does not change the original idea in old method. Actually ,in my company, we have strict rules on filename, so we can simply use A.split(). 
BTW, i think it is better we have some rules on filenames for a well-trained engineer. XD</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>86816</commentid>
    <comment_count>7</comment_count>
    <who name="yifan">153340508</who>
    <bug_when>2020-03-26 05:02:11 +0000</bug_when>
    <thetext>(In reply to comment #5)
&gt; Thanks for explaining, that helps and I can see the issue.
&gt; 
&gt; I am a little concerned the case handing &quot;*&quot; is lost, I&apos;m therefore worried
&gt; there may be some corner cases which aren&apos;t handled correctly. We should
&gt; also remove the commented code rather than just commenting it out.
&gt; 
&gt; I appreciate you&apos;re constrained upon how you can share patches, do you want
&gt; to fix up the patch here with a commit message and signed-off-by or does
&gt; someone else need to do that. I am grateful you have reported the problem as
&gt; it does sound like a good fix!

Hello Richard,
Do you have any more ideas on my commit https://git.yoctoproject.org/cgit/cgit.cgi/poky-contrib/commit/?h=happystudy-contrib/master&amp;id=8c9e646c0f5ecc7d239f518e2e6ef3be2f312dbe.
I know you are worrying about corner cases. I believe my fix has same function as the old one but faster,which i have explained before.And this will influence people building big project.
If you find any more corner cases please do not hesiatate to contact me .I would be glad to work with you guys to improve YOCTO.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>86936</commentid>
    <comment_count>8</comment_count>
    <who name="Richard Purdie">richard.purdie</who>
    <bug_when>2020-04-08 15:25:20 +0000</bug_when>
    <thetext>I have queued a modified version of this in master-next. I modified it to use a more advanced regex, retain the &quot;*&quot; check and cache the regex.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>87085</commentid>
    <comment_count>9</comment_count>
    <who name="Richard Purdie">richard.purdie</who>
    <bug_when>2020-04-26 06:02:05 +0000</bug_when>
    <thetext>http://git.yoctoproject.org/cgit.cgi/poky/commit/?id=8b1636763d6df9d68a50ed017ff0ed5f358b7321</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>