scripts: Adopted crc32c lib when available
Jumping from a simple Python implementation to the fully hardware accelerated crc32c library basically deletes any crc32c related bottlenecks: crc32c.py disk (1MiB) w/ crc32c lib: 0m0.027s crc32c.py disk (1MiB) w/o crc32c lib: 0m0.844s This uses the same try-import trick we use for inotify_simple, so we get the speed improvement without losing portability. --- In dbgbmap.py: dbgbmap.py w/ crc32c lib: 0m0.273s dbgbmap.py w/o crc32c lib: 0m0.697s dbgbmap.py w/ crc32c lib --no-ckdata: 0m0.269s dbgbmap.py w/o crc32c lib --no-ckdata: 0m0.490s dbgbmap.old.py: 0m0.231s The bulk of the runtime is still in Rbyd.fetch, but this is now dominated by leb128 decoding, which makes sense. We do ~twice as many fetches in the new dbgbmap.py in order to calculate the gcksum (which we then ignore...).
This commit is contained in:
+14
-6
@@ -20,6 +20,11 @@ import re
|
||||
import shlex
|
||||
import struct
|
||||
|
||||
try:
|
||||
import crc32c as crc32c_lib
|
||||
except ModuleNotFoundError:
|
||||
crc32c_lib = None
|
||||
|
||||
|
||||
TAG_NULL = 0x0000 ## 0x0000 v--- ---- ---- ----
|
||||
TAG_CONFIG = 0x0000 ## 0x00tt v--- ---- -ttt tttt
|
||||
@@ -190,12 +195,15 @@ def rbydaddr(s):
|
||||
return tuple(addr)
|
||||
|
||||
def crc32c(data, crc=0):
|
||||
crc ^= 0xffffffff
|
||||
for b in data:
|
||||
crc ^= b
|
||||
for j in range(8):
|
||||
crc = (crc >> 1) ^ ((crc & 1) * 0x82f63b78)
|
||||
return 0xffffffff ^ crc
|
||||
if crc32c_lib is not None:
|
||||
return crc32c_lib.crc32c(data, crc)
|
||||
else:
|
||||
crc ^= 0xffffffff
|
||||
for b in data:
|
||||
crc ^= b
|
||||
for j in range(8):
|
||||
crc = (crc >> 1) ^ ((crc & 1) * 0x82f63b78)
|
||||
return 0xffffffff ^ crc
|
||||
|
||||
def pmul(a, b):
|
||||
r = 0
|
||||
|
||||
Reference in New Issue
Block a user