mirror_edk2/BaseTools/Source/Python
Laszlo Ersek bd907fb638 BaseTools/GenFds: speed up Region.PadBuffer()
The current implementation calls both pack() and Buffer.write() Size
times. The new implementation calls both of these methods only once; the
full data to write are constructed locally [1]. The range() function is
replaced by xrange() because the latter is supposed to be faster / lighter
weight [2].

On my laptop, I tested the change as follows: I pre-built the series at
[3] with

  build -a X64 -p OvmfPkg/OvmfPkgX64.dsc -t GCC48 -b DEBUG \
      -D HTTP_BOOT_ENABLE -D SECURE_BOOT_ENABLE

(The series at [3] is relevant because it increases the size of one of the
padded regions by 8.5 MB, slowing down the build quite a bit.)

With all source code already compiled, repeating the above command takes
approximately 45 seconds. With the patch applied, it goes down to 29
seconds.

[1] http://stackoverflow.com/questions/27384093/fastest-way-to-write-huge-data-in-file
[2] https://docs.python.org/2/library/functions.html?highlight=xrange#xrange
[3] http://thread.gmane.org/gmane.comp.bios.edk2.devel/14214

We can also measure the impact with a synthetic test:

> import timeit
>
> test_old = """
> import struct, string, StringIO
> Size = (8 * 1024 + 512) * 1024
> Buffer = StringIO.StringIO()
> PadData = 0xFF
> for i in range(0, Size):
>     Buffer.write(struct.pack('B', PadData))
> """
>
> test_new = """
> import struct, string, StringIO
> Size = (8 * 1024 + 512) * 1024
> Buffer = StringIO.StringIO()
> PadByte = struct.pack('B', 0xFF)
> PadData = string.join(PadByte for i in xrange(0, Size))
> Buffer.write(PadData)
> """
>
> print(timeit.repeat(stmt=test_old, number=1, repeat=3))
> print(timeit.repeat(stmt=test_new, number=1, repeat=3))

The output is

[8.231637001037598, 8.81188416481018, 8.948754072189331]
[0.5503702163696289, 0.5461571216583252, 0.578315019607544]

Cc: Yonghong Zhu <yonghong.zhu@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Reviewed-by: Liming Gao <liming.gao@intel.com>
2016-07-12 13:19:27 +02:00
..
AutoGen BaseTools: ignore the binary LIB file in gen_libs 2016-06-15 08:56:17 +08:00
BPDG BaseTools/BPDG: Fix the bug to get the PCD Size 2016-03-14 11:33:12 +08:00
build BaseTools: Add support for $(FAMILY) macro 2016-07-05 15:51:21 +08:00
Common BaseTools: Fix bad macro expansion during tools_def.txt parsing 2016-05-27 12:31:00 +08:00
CommonDataClass BaseTools: Add support to merge Prebuild and Postbuild into build Process 2016-04-07 13:13:22 +08:00
Ecc BaseTools/ECC: Remove UNI checkpoint from ECC 2016-04-26 12:01:07 +08:00
Eot There is a limitation on WINDOWS OS for the length of entire file path can’t be larger than 255. There is an OS API provided by Microsoft to add “\\?\” before the path header to support the long file path. Enable this feature on basetools. 2014-08-15 03:06:48 +00:00
GenFds BaseTools/GenFds: speed up Region.PadBuffer() 2016-07-12 13:19:27 +02:00
GenPatchPcdTable BaseTools: Fix GenPatchPcdTable to support '-' characters in file names 2016-01-18 01:42:20 +00:00
PatchPcdValue BaseTools: Clean some coding style issues 2015-12-01 04:22:16 +00:00
Rsa2048Sha256Sign BaseTools: Do not create an empty file if Rsa2048Sha256Sign was failed. 2015-07-01 05:14:28 +00:00
Table BaseTools: Clean some coding style issues 2015-12-01 04:22:16 +00:00
TargetTool License header updated to match correct format. 2014-08-28 13:53:34 +00:00
Trim BaseTools: update the mail address for stack trace info 2016-03-11 12:29:59 +08:00
UPT BaseTools/UPT: UPT to Support UTF-8 2016-04-26 12:02:02 +08:00
Workspace BaseTools: fix the bug to build a compressed ROM image via .INF file 2016-06-04 21:22:00 +08:00
GNUmakefile Sync BaseTool trunk (version r2599) into EDKII BaseTools. 2013-08-23 02:18:16 +00:00
Makefile BaseTools: Support recent versions of cx_freeze. 2016-03-15 17:03:10 +08:00
sitecustomize.py License header updated to match correct format. 2014-08-28 13:53:34 +00:00