Fossil

Check-in [f5b559af94]
Login

Check-in [f5b559af94]

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Add test-brotli command to get some basic compression measurements. Closing this branch, as brotli is simply too slow for what we want to do.
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | brotli-compress
Files: files | file ages | folders
SHA3-256: f5b559af94346f86f04519024bfd8fd2fd3db52b339d7b3c8ad06005241c9dd6
User & Date: stephan 2025-04-01 12:16:46.109
Context
2025-04-01
12:16
Add test-brotli command to get some basic compression measurements. Closing this branch, as brotli is simply too slow for what we want to do. ... (Closed-Leaf check-in: f5b559af94 user: stephan tags: brotli-compress)
2025-03-31
21:04
Replace cgi.c:is_gzippable() with is_compressible() and add support for brotli compression to its decision-making process. There's still a lot to do before we can actually emit brotli compression. ... (check-in: 22e7b78dce user: stephan tags: brotli-compress)
Changes
Unified Diff Ignore Whitespace Patch
Changes to src/cgi.c.
565
566
567
568
569
570
571





572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
                 content_type_charset(zContentType));
    if( fossil_strcmp(zContentType,"application/x-fossil")==0 ){
      cgi_combine_header_and_body();
      blob_compress(&cgiContent[0], &cgiContent[0]);
    }

    if( iReplyStatus!=206 ){





      if( is_compressible(COMPRESSIBLE_ZLIB) ){
        int i;
        gzip_begin(0);
        for( i=0; i<2; i++ ){
          int size = blob_size(&cgiContent[i]);
          if( size>0 ) gzip_step(blob_buffer(&cgiContent[i]), size);
          blob_reset(&cgiContent[i]);
        }
        gzip_finish(&cgiContent[0]);
        blob_appendf(&hdr, "Content-Encoding: gzip\r\n");
        blob_appendf(&hdr, "Vary: Accept-Encoding\r\n");
      }
#ifdef HAVE_BROTLIENCODERCOMPRESS
      else if( is_compressible(COMPRESSIBLE_BROTLI) ){
        /* TODO */
      }
#endif
    }
    total_size = blob_size(&cgiContent[0]) + blob_size(&cgiContent[1]);
    if( iReplyStatus==206 ){
      blob_appendf(&hdr, "Content-Range: bytes %d-%d/%d\r\n",
              rangeStart, rangeEnd-1, total_size);
      total_size = rangeEnd - rangeStart;
    }







>
>
>
>
>












<
<
<
<
<







565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588





589
590
591
592
593
594
595
                 content_type_charset(zContentType));
    if( fossil_strcmp(zContentType,"application/x-fossil")==0 ){
      cgi_combine_header_and_body();
      blob_compress(&cgiContent[0], &cgiContent[0]);
    }

    if( iReplyStatus!=206 ){
#ifdef HAVE_BROTLIENCODERCOMPRESS
      if( 0 && is_compressible(COMPRESSIBLE_BROTLI) ){
        /* TODO */
      }else
#endif
      if( is_compressible(COMPRESSIBLE_ZLIB) ){
        int i;
        gzip_begin(0);
        for( i=0; i<2; i++ ){
          int size = blob_size(&cgiContent[i]);
          if( size>0 ) gzip_step(blob_buffer(&cgiContent[i]), size);
          blob_reset(&cgiContent[i]);
        }
        gzip_finish(&cgiContent[0]);
        blob_appendf(&hdr, "Content-Encoding: gzip\r\n");
        blob_appendf(&hdr, "Vary: Accept-Encoding\r\n");
      }





    }
    total_size = blob_size(&cgiContent[0]) + blob_size(&cgiContent[1]);
    if( iReplyStatus==206 ){
      blob_appendf(&hdr, "Content-Range: bytes %d-%d/%d\r\n",
              rangeStart, rangeEnd-1, total_size);
      total_size = rangeEnd - rangeStart;
    }
Changes to src/gzip.c.
134
135
136
137
138
139
140






























































  gzip_step(blob_buffer(&b), blob_size(&b));
  blob_reset(&b);
  gzip_finish(&b);
  blob_write_to_file(&b, zOut);
  blob_reset(&b);
  fossil_free(zOut);
}





































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
  gzip_step(blob_buffer(&b), blob_size(&b));
  blob_reset(&b);
  gzip_finish(&b);
  blob_write_to_file(&b, zOut);
  blob_reset(&b);
  fossil_free(zOut);
}

#ifdef HAVE_BROTLIENCODERCOMPRESS
#include <brotli/encode.h>

void brotli_compress(Blob *pIn, Blob *pOut){
  assert( pIn!=pOut );
}

/*
** COMMAND: test-brotli
**
** Usage: %fossil test-brotli ?-quality N? ?-text? FILENAME
**
** Compress a file using brotli.
**
*/
void test_brotli_compress(void){
  Blob b = empty_blob;
  Blob enc = empty_blob;
  char *zOut;
  size_t nMaxEnc;
  int timerId;
  sqlite3_uint64 nUsec;
  int rc;
  const char * zQuality = find_option("quality","q",1);
  const int bTextMode = find_option("text","t",0)!=0;
  const int iQuality = strtol(zQuality ? zQuality : "1", NULL, 10);
  if( g.argc!=3 ) usage("FILENAME");
  sqlite3_open(":memory:", &g.db);
  blob_read_from_file(&b, g.argv[2], ExtFILE);
  zOut = mprintf("%s.br", g.argv[2]);

  nMaxEnc = BrotliEncoderMaxCompressedSize((unsigned)blob_size(&b));
  fossil_print("Input size: %u bytes. ", (unsigned)blob_size(&b));
  blob_reserve(&enc, (unsigned)nMaxEnc);
  timerId = fossil_timer_start();
  rc = BrotliEncoderCompress(
    iQuality,
    BROTLI_DEFAULT_WINDOW,
    bTextMode ? BROTLI_MODE_TEXT : BROTLI_DEFAULT_MODE,
    (size_t)blob_size(&b),
    (const unsigned char*)blob_str(&b),
    &nMaxEnc,
    (unsigned char *)blob_str(&enc)
  );
  nUsec = fossil_timer_stop(timerId);
  if( 0==rc ){
    fossil_fatal("Compression failed for unknown reason");
  }
  fossil_print("BrotliEncoderCompress(q=%d, mode=%s) size=%u in %.2fms\n",
               iQuality, bTextMode ? "text" : "default",
               (unsigned)nMaxEnc,
               (double)(nUsec / 1000.0));
  if(0){
    fossil_print("TODO: actually compress\n");
    blob_write_to_file(&b, zOut);
  }
  blob_reset(&b);
  blob_reset(&enc);
  fossil_free(zOut);
}
#endif /* HAVE_BROTLIENCODERCOMPRESS */