From: "gaoliming via groups.io" <gaoliming=byosoft.com.cn@groups.io>
To: <davidr@ghs.com>, <devel@edk2.groups.io>
Subject: 回复: [edk2-devel] 回复: [edk2-devel] FDF parser performance degrades rapidly on non-trivially sized inputs
Date: Fri, 6 Dec 2024 09:41:02 +0800 [thread overview]
Message-ID: <006f01db477f$e8de19d0$ba9a4d70$@byosoft.com.cn> (raw)
In-Reply-To: <15637.1733446486644216677@groups.io>
[-- Attachment #1: Type: text/plain, Size: 5652 bytes --]
Thanks. I will try it.
发件人: via groups.io <davidr=ghs.com@groups.io>
发送时间: 2024年12月6日 8:55
收件人: gaoliming <gaoliming@byosoft.com.cn>; devel@edk2.groups.io
主题: Re: [edk2-devel] 回复: [edk2-devel] FDF parser performance degrades rapidly on non-trivially sized inputs
Here is the code I was testing with. You can probably reduce the changes down to just _SkipWhiteSpace(), but I haven't tried that yet.
diff --git a/BaseTools/Source/Python/GenFds/FdfParser.py b/BaseTools/Source/Python/GenFds/FdfParser.py
index feb4c72779..8c57720116 100644
--- a/BaseTools/Source/Python/GenFds/FdfParser.py
+++ b/BaseTools/Source/Python/GenFds/FdfParser.py
@@ -12,6 +12,7 @@
#
from __future__ import print_function
from __future__ import absolute_import
+from io import StringIO
from re import compile, DOTALL
from string import hexdigits
from uuid import UUID
@@ -253,7 +254,7 @@ class FdfParser:
self.CurrentFdName = None
self.CurrentFvName = None
self._Token = ""
- self._SkippedChars = ""
+ self._SkippedChars = StringIO()
GlobalData.gFdfParser = self
# Used to section info
@@ -276,7 +277,7 @@ class FdfParser:
def _SkipWhiteSpace(self):
while not self._EndOfFile():
if self._CurrentChar() in {TAB_PRINTCHAR_NUL, T_CHAR_CR, TAB_LINE_BREAK, TAB_SPACE_SPLIT, T_CHAR_TAB}:
- self._SkippedChars += str(self._CurrentChar())
+ self._SkippedChars.write(str(self._CurrentChar()))
self._GetOneChar()
else:
return
@@ -696,7 +697,7 @@ class FdfParser:
Header = self._Token
if not self._Token.endswith(TAB_SECTION_END):
self._SkipToToken(TAB_SECTION_END)
- Header += self._SkippedChars
+ Header += self._SkippedChars.getvalue()
if Header.find('$(') != -1:
raise Warning("macro cannot be used in section header", self.FileName, self.CurrentLineNumber)
self._SectionHeaderParser(Header)
@@ -1226,7 +1227,7 @@ class FdfParser:
raise Warning(QuoteToUse, self.FileName, self.CurrentLineNumber)
if currentLineNumber != self.CurrentLineNumber:
raise Warning(QuoteToUse, self.FileName, self.CurrentLineNumber)
- self._Token = self._SkippedChars.rstrip(QuoteToUse)
+ self._Token = self._SkippedChars.getvalue().rstrip(QuoteToUse)
return True
## _SkipToToken() method
@@ -1243,7 +1244,7 @@ class FdfParser:
def _SkipToToken(self, String, IgnoreCase = False):
StartPos = self.GetFileBufferPos()
- self._SkippedChars = ""
+ self._SkippedChars = StringIO()
while not self._EndOfFile():
index = -1
if IgnoreCase:
@@ -1252,13 +1253,13 @@ class FdfParser:
index = self._CurrentLine()[self.CurrentOffsetWithinLine: ].find(String)
if index == 0:
self.CurrentOffsetWithinLine += len(String)
- self._SkippedChars += String
+ self._SkippedChars.write(String)
return True
- self._SkippedChars += str(self._CurrentChar())
+ self._SkippedChars.write(str(self._CurrentChar()))
self._GetOneChar()
self.SetFileBufferPos(StartPos)
- self._SkippedChars = ""
+ self._SkippedChars = StringIO()
return False
## GetFileBufferPos() method
@@ -2890,7 +2891,7 @@ class FdfParser:
if not self._SkipToToken(T_CHAR_BRACE_R):
raise Warning.Expected("Depex expression ending '}'", self.FileName, self.CurrentLineNumber)
- DepexSectionObj.Expression = self._SkippedChars.rstrip(T_CHAR_BRACE_R)
+ DepexSectionObj.Expression = self._SkippedChars.getvalue().rstrip(T_CHAR_BRACE_R)
Obj.SectionList.append(DepexSectionObj)
elif self._IsKeyword("SUBTYPE_GUID"):
@@ -3525,7 +3526,7 @@ class FdfParser:
if not self._SkipToToken(TAB_SPLIT):
raise Warning.Expected("'.'", self.FileName, self.CurrentLineNumber)
- Arch = self._SkippedChars.rstrip(TAB_SPLIT)
+ Arch = self._SkippedChars.getvalue().rstrip(TAB_SPLIT)
ModuleType = self._GetModuleType()
Also, if you would like to profile the build process you can apply this patch.
diff --git a/BaseTools/Source/Python/build/build.py b/BaseTools/Source/Python/build/build.py
index 51fb1f433e..396729efd9 100755
--- a/BaseTools/Source/Python/build/build.py
+++ b/BaseTools/Source/Python/build/build.py
@@ -2778,12 +2778,18 @@ def Main():
Log_Agent.join()
return ReturnCode
+import cProfile
+
if __name__ == '__main__':
try:
mp.set_start_method('spawn')
except:
pass
- r = Main()
+
+ with cProfile.Profile() as pr:
+ r = Main()
+ pr.print_stats('tottime')
+
## 0-127 is a safe return range, and 1 is a standard default error
if r < 0 or r > 127: r = 1
sys.exit(r)
-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#120885): https://edk2.groups.io/g/devel/message/120885
Mute This Topic: https://groups.io/mt/109951333/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-
[-- Attachment #2: Type: text/html, Size: 11880 bytes --]
prev parent reply other threads:[~2024-12-06 1:41 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-28 7:55 [edk2-devel] FDF parser performance degrades rapidly on non-trivially sized inputs davidr via groups.io
2024-12-04 10:22 ` Ard Biesheuvel via groups.io
2024-12-04 18:00 ` davidr via groups.io
2024-12-05 0:50 ` 回复: " gaoliming via groups.io
2024-12-06 0:54 ` [edk2-devel] " davidr via groups.io
2024-12-06 1:41 ` gaoliming via groups.io [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='006f01db477f$e8de19d0$ba9a4d70$@byosoft.com.cn' \
--to=devel@edk2.groups.io \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox