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:
@@ -9,6 +9,11 @@ import os
|
|||||||
import struct
|
import struct
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
try:
|
||||||
|
import crc32c as crc32c_lib
|
||||||
|
except ModuleNotFoundError:
|
||||||
|
crc32c_lib = None
|
||||||
|
|
||||||
|
|
||||||
def openio(path, mode='r', buffering=-1):
|
def openio(path, mode='r', buffering=-1):
|
||||||
# allow '-' for stdin/stdout
|
# allow '-' for stdin/stdout
|
||||||
@@ -22,6 +27,9 @@ def openio(path, mode='r', buffering=-1):
|
|||||||
return open(path, mode, buffering)
|
return open(path, mode, buffering)
|
||||||
|
|
||||||
def crc32c(data, crc=0):
|
def crc32c(data, crc=0):
|
||||||
|
if crc32c_lib is not None:
|
||||||
|
return crc32c_lib.crc32c(data, crc)
|
||||||
|
else:
|
||||||
crc ^= 0xffffffff
|
crc ^= 0xffffffff
|
||||||
for b in data:
|
for b in data:
|
||||||
crc ^= b
|
crc ^= b
|
||||||
|
|||||||
@@ -7,6 +7,11 @@ if __name__ == "__main__":
|
|||||||
import itertools as it
|
import itertools as it
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
try:
|
||||||
|
import crc32c as crc32c_lib
|
||||||
|
except ModuleNotFoundError:
|
||||||
|
crc32c_lib = None
|
||||||
|
|
||||||
|
|
||||||
# some ways of block geometry representations
|
# some ways of block geometry representations
|
||||||
# 512 -> 512
|
# 512 -> 512
|
||||||
@@ -79,6 +84,9 @@ def xxd(data, width=16):
|
|||||||
for b in map(chr, data[i:i+width])))
|
for b in map(chr, data[i:i+width])))
|
||||||
|
|
||||||
def crc32c(data, crc=0):
|
def crc32c(data, crc=0):
|
||||||
|
if crc32c_lib is not None:
|
||||||
|
return crc32c_lib.crc32c(data, crc)
|
||||||
|
else:
|
||||||
crc ^= 0xffffffff
|
crc ^= 0xffffffff
|
||||||
for b in data:
|
for b in data:
|
||||||
crc ^= b
|
crc ^= b
|
||||||
|
|||||||
@@ -23,6 +23,11 @@ try:
|
|||||||
except ModuleNotFoundError:
|
except ModuleNotFoundError:
|
||||||
inotify_simple = None
|
inotify_simple = None
|
||||||
|
|
||||||
|
try:
|
||||||
|
import crc32c as crc32c_lib
|
||||||
|
except ModuleNotFoundError:
|
||||||
|
crc32c_lib = None
|
||||||
|
|
||||||
|
|
||||||
TAG_NULL = 0x0000 ## 0x0000 v--- ---- ---- ----
|
TAG_NULL = 0x0000 ## 0x0000 v--- ---- ---- ----
|
||||||
TAG_CONFIG = 0x0000 ## 0x00tt v--- ---- -ttt tttt
|
TAG_CONFIG = 0x0000 ## 0x00tt v--- ---- -ttt tttt
|
||||||
@@ -161,6 +166,9 @@ def rbydaddr(s):
|
|||||||
return tuple(addr)
|
return tuple(addr)
|
||||||
|
|
||||||
def crc32c(data, crc=0):
|
def crc32c(data, crc=0):
|
||||||
|
if crc32c_lib is not None:
|
||||||
|
return crc32c_lib.crc32c(data, crc)
|
||||||
|
else:
|
||||||
crc ^= 0xffffffff
|
crc ^= 0xffffffff
|
||||||
for b in data:
|
for b in data:
|
||||||
crc ^= b
|
crc ^= b
|
||||||
|
|||||||
@@ -20,6 +20,11 @@ import re
|
|||||||
import shlex
|
import shlex
|
||||||
import struct
|
import struct
|
||||||
|
|
||||||
|
try:
|
||||||
|
import crc32c as crc32c_lib
|
||||||
|
except ModuleNotFoundError:
|
||||||
|
crc32c_lib = None
|
||||||
|
|
||||||
|
|
||||||
TAG_NULL = 0x0000 ## 0x0000 v--- ---- ---- ----
|
TAG_NULL = 0x0000 ## 0x0000 v--- ---- ---- ----
|
||||||
TAG_CONFIG = 0x0000 ## 0x00tt v--- ---- -ttt tttt
|
TAG_CONFIG = 0x0000 ## 0x00tt v--- ---- -ttt tttt
|
||||||
@@ -190,6 +195,9 @@ def rbydaddr(s):
|
|||||||
return tuple(addr)
|
return tuple(addr)
|
||||||
|
|
||||||
def crc32c(data, crc=0):
|
def crc32c(data, crc=0):
|
||||||
|
if crc32c_lib is not None:
|
||||||
|
return crc32c_lib.crc32c(data, crc)
|
||||||
|
else:
|
||||||
crc ^= 0xffffffff
|
crc ^= 0xffffffff
|
||||||
for b in data:
|
for b in data:
|
||||||
crc ^= b
|
crc ^= b
|
||||||
|
|||||||
@@ -12,6 +12,11 @@ import math as mt
|
|||||||
import os
|
import os
|
||||||
import struct
|
import struct
|
||||||
|
|
||||||
|
try:
|
||||||
|
import crc32c as crc32c_lib
|
||||||
|
except ModuleNotFoundError:
|
||||||
|
crc32c_lib = None
|
||||||
|
|
||||||
|
|
||||||
TAG_NULL = 0x0000 ## 0x0000 v--- ---- ---- ----
|
TAG_NULL = 0x0000 ## 0x0000 v--- ---- ---- ----
|
||||||
TAG_CONFIG = 0x0000 ## 0x00tt v--- ---- -ttt tttt
|
TAG_CONFIG = 0x0000 ## 0x00tt v--- ---- -ttt tttt
|
||||||
@@ -117,6 +122,9 @@ def rbydaddr(s):
|
|||||||
return tuple(addr)
|
return tuple(addr)
|
||||||
|
|
||||||
def crc32c(data, crc=0):
|
def crc32c(data, crc=0):
|
||||||
|
if crc32c_lib is not None:
|
||||||
|
return crc32c_lib.crc32c(data, crc)
|
||||||
|
else:
|
||||||
crc ^= 0xffffffff
|
crc ^= 0xffffffff
|
||||||
for b in data:
|
for b in data:
|
||||||
crc ^= b
|
crc ^= b
|
||||||
|
|||||||
@@ -7,6 +7,11 @@ if __name__ == "__main__":
|
|||||||
import itertools as it
|
import itertools as it
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
try:
|
||||||
|
import crc32c as crc32c_lib
|
||||||
|
except ModuleNotFoundError:
|
||||||
|
crc32c_lib = None
|
||||||
|
|
||||||
|
|
||||||
# some ways of block geometry representations
|
# some ways of block geometry representations
|
||||||
# 512 -> 512
|
# 512 -> 512
|
||||||
@@ -79,6 +84,9 @@ def xxd(data, width=16):
|
|||||||
for b in map(chr, data[i:i+width])))
|
for b in map(chr, data[i:i+width])))
|
||||||
|
|
||||||
def crc32c(data, crc=0):
|
def crc32c(data, crc=0):
|
||||||
|
if crc32c_lib is not None:
|
||||||
|
return crc32c_lib.crc32c(data, crc)
|
||||||
|
else:
|
||||||
crc ^= 0xffffffff
|
crc ^= 0xffffffff
|
||||||
for b in data:
|
for b in data:
|
||||||
crc ^= b
|
crc ^= b
|
||||||
|
|||||||
@@ -13,6 +13,11 @@ import os
|
|||||||
import struct
|
import struct
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
try:
|
||||||
|
import crc32c as crc32c_lib
|
||||||
|
except ModuleNotFoundError:
|
||||||
|
crc32c_lib = None
|
||||||
|
|
||||||
|
|
||||||
TAG_NULL = 0x0000 ## 0x0000 v--- ---- ---- ----
|
TAG_NULL = 0x0000 ## 0x0000 v--- ---- ---- ----
|
||||||
TAG_CONFIG = 0x0000 ## 0x00tt v--- ---- -ttt tttt
|
TAG_CONFIG = 0x0000 ## 0x00tt v--- ---- -ttt tttt
|
||||||
@@ -118,6 +123,9 @@ def rbydaddr(s):
|
|||||||
return tuple(addr)
|
return tuple(addr)
|
||||||
|
|
||||||
def crc32c(data, crc=0):
|
def crc32c(data, crc=0):
|
||||||
|
if crc32c_lib is not None:
|
||||||
|
return crc32c_lib.crc32c(data, crc)
|
||||||
|
else:
|
||||||
crc ^= 0xffffffff
|
crc ^= 0xffffffff
|
||||||
for b in data:
|
for b in data:
|
||||||
crc ^= b
|
crc ^= b
|
||||||
|
|||||||
@@ -12,6 +12,11 @@ import math as mt
|
|||||||
import os
|
import os
|
||||||
import struct
|
import struct
|
||||||
|
|
||||||
|
try:
|
||||||
|
import crc32c as crc32c_lib
|
||||||
|
except ModuleNotFoundError:
|
||||||
|
crc32c_lib = None
|
||||||
|
|
||||||
|
|
||||||
TAG_NULL = 0x0000 ## 0x0000 v--- ---- ---- ----
|
TAG_NULL = 0x0000 ## 0x0000 v--- ---- ---- ----
|
||||||
TAG_CONFIG = 0x0000 ## 0x00tt v--- ---- -ttt tttt
|
TAG_CONFIG = 0x0000 ## 0x00tt v--- ---- -ttt tttt
|
||||||
@@ -117,6 +122,9 @@ def rbydaddr(s):
|
|||||||
return tuple(addr)
|
return tuple(addr)
|
||||||
|
|
||||||
def crc32c(data, crc=0):
|
def crc32c(data, crc=0):
|
||||||
|
if crc32c_lib is not None:
|
||||||
|
return crc32c_lib.crc32c(data, crc)
|
||||||
|
else:
|
||||||
crc ^= 0xffffffff
|
crc ^= 0xffffffff
|
||||||
for b in data:
|
for b in data:
|
||||||
crc ^= b
|
crc ^= b
|
||||||
|
|||||||
@@ -12,6 +12,11 @@ import math as mt
|
|||||||
import os
|
import os
|
||||||
import struct
|
import struct
|
||||||
|
|
||||||
|
try:
|
||||||
|
import crc32c as crc32c_lib
|
||||||
|
except ModuleNotFoundError:
|
||||||
|
crc32c_lib = None
|
||||||
|
|
||||||
|
|
||||||
COLORS = [
|
COLORS = [
|
||||||
'34', # blue
|
'34', # blue
|
||||||
@@ -127,6 +132,9 @@ def rbydaddr(s):
|
|||||||
return tuple(addr)
|
return tuple(addr)
|
||||||
|
|
||||||
def crc32c(data, crc=0):
|
def crc32c(data, crc=0):
|
||||||
|
if crc32c_lib is not None:
|
||||||
|
return crc32c_lib.crc32c(data, crc)
|
||||||
|
else:
|
||||||
crc ^= 0xffffffff
|
crc ^= 0xffffffff
|
||||||
for b in data:
|
for b in data:
|
||||||
crc ^= b
|
crc ^= b
|
||||||
|
|||||||
Reference in New Issue
Block a user