Skip to content

Commit

Permalink
minor split optimization
Browse files Browse the repository at this point in the history
let's fill the initial stats directly into target fingerprint
  • Loading branch information
Cyan4973 committed Oct 21, 2024
1 parent e1c373f commit e468136
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
10 changes: 5 additions & 5 deletions lib/compress/zstd_preSplit.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#define BLOCKSIZE_MIN 3500
#define THRESHOLD_PENALTY_RATE 16
#define THRESHOLD_BASE (THRESHOLD_PENALTY_RATE - 2)
#define THRESHOLD_PENALTY 4
#define THRESHOLD_PENALTY 3

#define HASHLENGTH 2
#define HASHLOG 10
Expand Down Expand Up @@ -84,8 +84,8 @@ static int compareFingerprints(const FingerPrint* ref,
const FingerPrint* newfp,
int penalty)
{
if (ref->nbEvents <= BLOCKSIZE_MIN)
return 0;
assert(ref->nbEvents > 0);
assert(newfp->nbEvents > 0);
{ S64 p50 = ref->nbEvents * newfp->nbEvents;
S64 deviation = fpDistance(ref, newfp);
S64 threshold = p50 * (THRESHOLD_BASE + penalty) / THRESHOLD_PENALTY_RATE;
Expand Down Expand Up @@ -140,7 +140,8 @@ size_t ZSTD_splitBlock_4k(const void* src, size_t srcSize,
assert(wkspSize >= sizeof(FPStats)); (void)wkspSize;

initStats(fpstats);
for (pos = 0; pos < blockSizeMax;) {
recordFingerprint(&fpstats->pastEvents, p, CHUNKSIZE);
for (pos = CHUNKSIZE; pos < blockSizeMax; pos += CHUNKSIZE) {
assert(pos <= blockSizeMax - CHUNKSIZE);
recordFingerprint(&fpstats->newEvents, p + pos, CHUNKSIZE);
if (compareFingerprints(&fpstats->pastEvents, &fpstats->newEvents, penalty)) {
Expand All @@ -150,7 +151,6 @@ size_t ZSTD_splitBlock_4k(const void* src, size_t srcSize,
ZSTD_memset(&fpstats->newEvents, 0, sizeof(fpstats->newEvents));
penalty = penalty - 1 + (penalty == 0);
}
pos += CHUNKSIZE;
}
return blockSizeMax;
(void)flushEvents; (void)removeEvents;
Expand Down
4 changes: 4 additions & 0 deletions lib/compress/zstd_preSplit.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ extern "C" {
/* note:
* @workspace must be aligned on 8-bytes boundaries
* @wkspSize must be at least >= ZSTD_SLIPBLOCK_WORKSPACESIZE
* note2:
* for the time being, this function only accepts full 128 KB blocks,
* therefore @blockSizeMax must be == 128 KB.
* This could be extended to smaller sizes in the future.
*/
size_t ZSTD_splitBlock_4k(const void* src, size_t srcSize, size_t blockSizeMax, void* workspace, size_t wkspSize);

Expand Down

0 comments on commit e468136

Please sign in to comment.