Skip to content

Commit

Permalink
Merge pull request #1204 from heshpdx:master
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 697922880
  • Loading branch information
copybara-github committed Nov 19, 2024
2 parents f25050c + 8c6d25f commit 2b6efcb
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
6 changes: 4 additions & 2 deletions c/enc/block_splitter_inc.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ static size_t FN(FindBlocks)(const DataType* data, const size_t length,
size_t insert_cost_ix = symbol * num_histograms;
double min_cost = 1e99;
double block_switch_cost = block_switch_bitcost;
static const size_t prologue_length = 2000;
static const double multiplier = 0.07 / 2000;
size_t k;
for (k = 0; k < num_histograms; ++k) {
/* We are coding the symbol with entropy code k. */
Expand All @@ -128,8 +130,8 @@ static size_t FN(FindBlocks)(const DataType* data, const size_t length,
}
}
/* More blocks for the beginning. */
if (byte_ix < 2000) {
block_switch_cost *= 0.77 + 0.07 * (double)byte_ix / 2000;
if (byte_ix < prologue_length) {
block_switch_cost *= 0.77 + multiplier * (double)byte_ix;
}
for (k = 0; k < num_histograms; ++k) {
cost[k] -= min_cost;
Expand Down
3 changes: 2 additions & 1 deletion c/enc/encode.c
Original file line number Diff line number Diff line change
Expand Up @@ -437,9 +437,10 @@ static BROTLI_BOOL ShouldCompress(
if ((double)num_literals > 0.99 * (double)bytes) {
uint32_t literal_histo[256] = { 0 };
static const uint32_t kSampleRate = 13;
static const double kInvSampleRate = 1.0 / 13.0;
static const double kMinEntropy = 7.92;
const double bit_cost_threshold =
(double)bytes * kMinEntropy / kSampleRate;
(double)bytes * kMinEntropy * kInvSampleRate;
size_t t = (bytes + kSampleRate - 1) / kSampleRate;
uint32_t pos = (uint32_t)last_flush_pos;
size_t i;
Expand Down
6 changes: 4 additions & 2 deletions c/enc/literal_cost.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ static void EstimateBitCostsForLiteralsUTF8(size_t pos, size_t len, size_t mask,
size_t utf8_pos = UTF8Position(last_c, c, max_utf8);
size_t masked_pos = (pos + i) & mask;
size_t histo = histogram[256 * utf8_pos + data[masked_pos]];
static const size_t prologue_length = 2000;
static const double multiplier = 0.35 / 2000;
double lit_cost;
if (histo == 0) {
histo = 1;
Expand All @@ -120,8 +122,8 @@ static void EstimateBitCostsForLiteralsUTF8(size_t pos, size_t len, size_t mask,
Perhaps because the entropy source is changing its properties
rapidly in the beginning of the file, perhaps because the beginning
of the data is a statistical "anomaly". */
if (i < 2000) {
lit_cost += 0.7 - ((double)(2000 - i) / 2000.0 * 0.35);
if (i < prologue_length) {
lit_cost += 0.35 + multiplier * (double)i;
}
cost[i] = (float)lit_cost;
}
Expand Down

0 comments on commit 2b6efcb

Please sign in to comment.