Delta encoding

Type of data transmission method

Not to be confused with Elias delta coding or delta modulation.

Delta encoding is a way of storing or transmitting data in the form of differences (deltas) between sequential data rather than complete files; more generally this is known as data differencing. Delta encoding is sometimes called delta compression, particularly where archival histories of changes are required (e.g., in revision control software).

The differences are recorded in discrete files called "deltas" or "diffs". In situations where differences are small – for example, the change of a few words in a large document or the change of a few records in a large table – delta encoding greatly reduces data redundancy. Collections of unique deltas are substantially more space-efficient than their non-encoded equivalents.

From a logical point of view, the difference between two data values is the information required to obtain one value from the other – see relative entropy. The difference between identical values (under some equivalence) is often called 0 or the neutral element.

## Simple example

[edit]

Perhaps the simplest example is storing values of bytes as differences (deltas) between sequential values, rather than the values themselves. So, instead of 2, 4, 6, 9, 7, we would store 2, 2, 2, 3, −2. This reduces the variance (range) of the values when neighbor samples are correlated, enabling a lower bit usage for the same data. IFF 8SVX sound format applies this encoding to raw sound data before applying compression to it. Not even all 8-bit sound samples compress better when delta encoded, and the usability of delta encoding is even smaller for 16-bit and better samples. Therefore, compression algorithms often choose to delta encode only when the compression is better than without. However, in video compression, delta frames can considerably reduce frame size and are used in virtually every video compression codec.

## Definition

[edit]

A delta can be defined in 2 ways, symmetric delta and directed delta. A symmetric delta can be expressed as

Δ ( v e r s i o n 1 , v e r s i o n 2 ) = ( v e r s i o n 1 ∖ v e r s i o n 2 ) ∪ ( v e r s i o n 2 ∖ v e r s i o n 1 ) , {\displaystyle \Delta (version_{1},version_{2})=(version_{1}\setminus version_{2})\cup (version_{2}\setminus version_{1}),}

A directed delta, also called a change, is a sequence of (elementary) change operations which, when applied to  v e r s i o n 1 {\displaystyle version_{1}} , yields another,  v e r s i o n 2 {\displaystyle version_{2}} (note the correspondence to transaction logs in databases). In computer implementations, they typically take the form of a language with two commands: copy data from  v e r s i o n 1 {\displaystyle version_{1}} and write literal data.

### Variants

[edit]

A variation of delta encoding which encodes differences between the prefixes or suffixes of strings is called incremental encoding. It is particularly effective for sorted lists with small differences between strings, such as a list of words from a dictionary.

## Implementation issues

[edit]

The nature of the data to be encoded influences the effectiveness of a particular compression algorithm.

Delta encoding performs best when data has small or constant variation; for an unsorted data set, there may be little to no compression possible with this method.

In delta encoded transmission over a network where only a single copy of the file is available at each end of the communication channel, special error control codes are used to detect which parts of the file have changed since its previous version. For example, rsync uses a rolling checksum algorithm based on Mark Adler's adler-32 checksum.

## Sample C code

[edit]

The following C code performs a simple form of delta encoding and decoding on a sequence of characters:

void delta_encode(unsigned char *buffer, int length)

unsigned char last = 0;
for (int i = 0; i < length; i++)

unsigned char current = buffer[i];
buffer[i] = current - last;
last = current;

void delta_decode(unsigned char *buffer, int length)

unsigned char last = 0;
for (int i = 0; i < length; i++)

unsigned char delta = buffer[i];
buffer[i] = delta + last;
last = buffer[i];

## Examples

[edit]

### Binary delta compression

[edit]

This section is an excerpt from Binary delta compression.[edit]

Binary delta compression is a technology used in software deployment for distributing patches.

### Delta encoding in HTTP

[edit]

Another instance of use of delta encoding is RFC 3229, "Delta encoding in HTTP", which proposes that HTTP servers should be able to send updated Web pages in the form of differences between versions (deltas), which should decrease Internet traffic, as most pages change slowly over time, rather than being completely rewritten repeatedly:

> This document describes how delta encoding can be supported as a compatible extension to HTTP/1.1.

> Many HTTP (Hypertext Transport Protocol) requests cause the retrieval of slightly modified instances of resources for which the client already has a cache entry. Research has shown that such modifying updates are frequent, and that the modifications are typically much smaller than the actual entity. In such cases, HTTP would make more efficient use of network bandwidth if it could transfer a minimal description of the changes, rather than the entire new instance of the resource.

> [...] We believe that it might be possible to support rsync using the "instance manipulation" framework described later in this document, but this has not been worked out in any detail.

The suggested rsync-based framework was implemented in the rproxy system as a pair of HTTP proxies.[1] Like the basic vcdiff-based implementation, both systems are rarely used.

### Delta copying

[edit]

Delta copying is a fast way of copying a file that is partially changed, when a previous version is present on the destination location. With delta copying, only the changed part of a file is copied. It is usually used in backup or file copying software, often to save bandwidth when copying between computers over a private network or the internet. One notable open-source example is rsync.[2][3][4]

#### Online backup

[edit]

Main article: Online backup services

Many of the online backup services adopt this methodology, often known simply as deltas, in order to give their users previous versions of the same file from previous backups. This reduces associated costs, not only in the amount of data that has to be stored as differing versions (as the whole of each changed version of a file has to be offered for users to access), but also those costs in the uploading (and sometimes the downloading) of each file that has been updated (by just the smaller delta having to be used, rather than the whole file).

#### Delta updates

[edit]

Main article: delta update

For large software packages, there is usually little data changed between versions. Many vendors choose to use delta transfers to save time and bandwidth.

### Diff

[edit]

Main article: Diff

Diff is a file comparison program, which is mainly used for text files. By default, it generates symmetric deltas that are reversible. Two formats used for software patches, context and unified, provides additional context lines that allow for tolerating shifts in line number.

### Git

[edit]

Main article: Git (software)

The Git source code control system employs delta compression in an auxiliary "git repack" operation. Objects in the repository that have not yet been delta-compressed ("loose objects") are compared against a heuristically chosen subset of all other objects, and the common data and differences are concatenated into a "pack file" which is then compressed using conventional methods. In common use cases, where source or data files are changed incrementally between commits, this can result in significant space savings. The repack operation is typically performed as part of the " git gc"[5] process, which is triggered automatically when the numbers of loose objects or pack files exceed configured thresholds.

The format is documented in the pack-format page of the Git documentation. It implements a directed delta.[6]

### VCDIFF

[edit]

Main article: VCDIFF

One general format for directed delta encoding is VCDIFF, described in RFC 3284. Free software implementations include Xdelta and open-vcdiff.

### GDIFF

[edit]

Generic Diff Format (GDIFF) is another directed delta encoding format. It was submitted to W3C in 1997.[7] In many cases, VCDIFF has better compression rate than GDIFF.

### bsdiff

[edit]

Bsdiff is a binary diff program using suffix sorting. For executables that contain many changes in pointer addresses, it performs better than VCDIFF-type "copy and literal" encodings. The intent is to find a way to generate a small diff without needing to parse assembly code (as in Google's Courgette). Bsdiff achieves this by allowing "copy" matches with errors, which are then corrected using an extra "add" array of bytewise differences. Since this array is mostly either zero or repeated values for offset changes, it takes up little space after compression.[8]

Bsdiff is useful for delta updates. Google uses bsdiff in Chromium and Android. The deltarpm feature of the RPM Package Manager is based on a heavily modified bsdiff that can use a hash table for matching.[9] FreeBSD also uses bsdiff for updates.[10]

Since the 4.3 release of bsdiff in 2005, various improvements or fixes have been produced for it. Google maintains multiple versions of the code for each of its products.[11] FreeBSD takes many of Google's compatible changes, mainly a vulnerability fix and a switch to the faster `divsufsort` suffix-sorting routine.[12] Debian has a series of performance tweaks to the program.[13]

ddelta is a rewrite of bsdiff proposed for use in Debian's delta updates. Among other efficiency improvements, it uses a sliding window to reduce memory and CPU cost.[14]

## See also

[edit]

* Data differencing – Method for compressing changes over time
* Interleaved deltas
* Source Code Control System – Version control system for source code
* String-to-string correction problem
* Xdelta: open-source delta encoder

## References

[edit]

1. ^ "rproxy: introduction". rproxy.samba.org.
2. ^ "Feature request: Delta copying - 2BrightSparks". Archived from the original on 2016-03-13. Retrieved 2016-04-29.
3. ^ "Bvckup 2 | Forum | How delta copying works".
4. ^ [1][permanent dead link]
5. ^ "Git - git-gc Documentation". git-scm.com. Retrieved November 9, 2024.
6. ^ "Git - pack-format Documentation". Git documentation. Retrieved 13 January 2020.
7. ^ "Generic Diff Format Specification". www.w3.org.
8. ^ "Binary diff". www.daemonology.net. Retrieved November 9, 2024.
9. ^ "rpmdelta/delta.c". rpm-software-management. 3 July 2019. Retrieved 13 January 2020.
10. ^ Anonymous (May 2016). "NON-CRYPTANALYTIC ATTACKS AGAINST FREEBSD UPDATE COMPONENTS". GitHub Gist.
11. ^ "xtraeme/bsdiff-chromium: README.chromium". GitHub. 2012.; "courgette/third_party/bsdiff/README.chromium - chromium/src". Git at Google.; "android/platform/external/bsdiff/". Git at Google.
12. ^ "History for freebsd/usr.bin/bsdiff". GitHub.
13. ^ "Package: bsdiff". Debian Patch Tracker.
14. ^ Klode, Julian. "julian-klode/ddelta". GitHub. Retrieved 13 January 2020.

## External links

[edit]

* RFC 3229 – Delta Encoding in HTTP

* v
* t
* e

Data compression methods

Lossless
type|

| Entropy|

* Adaptive coding
* Arithmetic
* Asymmetric numeral systems
* Golomb
* Huffman
* Adaptive
* Canonical
* Modified
* Range
* Shannon
* Shannon–Fano
* Shannon–Fano–Elias
* Tunstall
* Unary
* Universal
* Exp-Golomb
* Fibonacci
* Gamma
* Levenshtein

|

Dictionary|

* Byte-pair encoding
* Lempel–Ziv
* 842
* LZ4
* LZJB
* LZO
* LZRW
* LZSS
* LZW
* LZWL
* Snappy

Other|

* BWT
* CTW
* CM
* Delta
* Incremental
* DMC
* DPCM
* Grammar
* Re-Pair
* Sequitur
* LDCT
* MTF
* PAQ
* PPM
* RLE

Hybrid|

* LZ77 + Huffman
* Deflate
* LZX
* LZS
* LZ77 + ANS
* LZFSE
* LZ77 + Huffman + ANS
* Zstandard
* LZ77 + Huffman + context
* Brotli
* LZSS + Huffman
* LHA/LZH
* LZ77 + Range
* LZMA
* LZHAM
* RLE + BWT + MTF + Huffman
* bzip2

Lossy
type|

| Transform|

* Discrete cosine transform
* DCT
* MDCT
* DST
* FFT
* Wavelet
* Daubechies
* DWT
* SPIHT

|

Predictive|

* DPCM
* ADPCM
* LPC
* ACELP
* CELP
* LAR
* LSP
* WLPC
* Motion
* Compensation
* Estimation
* Vector
* Psychoacoustic

Audio|

| Concepts|

* Bit rate
* ABR
* CBR
* VBR
* Companding
* Convolution
* Dynamic range
* Latency
* Nyquist–Shannon theorem
* Sampling
* Silence compression
* Sound quality
* Speech coding
* Sub-band coding

|

Codec
parts|

* A-law
* μ-law
* DPCM
* ADPCM
* DM
* FT
* FFT
* LPC
* ACELP
* CELP
* LAR
* LSP
* WLPC
* MDCT
* Psychoacoustic model

Image|

| Concepts|

* Chroma subsampling
* Coding tree unit
* Color space
* Compression artifact
* Image resolution
* Macroblock
* Pixel
* PSNR
* Quantization
* Standard test image
* Texture compression

|

Methods|

* Chain code
* DCT
* Deflate
* Fractal
* KLT
* LP
* RLE
* Wavelet
* Daubechies
* DWT
* EZW
* SPIHT

Video|

| Concepts|

* Bit rate
* ABR
* CBR
* VBR
* Display resolution
* Frame
* Frame rate
* Frame types
* Interlace
* Video characteristics
* Video quality

|

Codec
parts|

* DCT
* DPCM
* Deblocking filter
* Lapped transform
* Motion
* Compensation
* Estimation
* Vector
* Wavelet
* Daubechies
* DWT

Theory|

* Compressed data structures
* Compressed suffix array
* FM-index
* Entropy
* Information theory
* Timeline
* Kolmogorov complexity
* Prefix code
* Quantization
* Rate–distortion
* Redundancy
* Symmetry
* Smallest grammar problem

Community|

* Hutter Prize

People|

* Mark Adler
* Phil Katz

* v
* t
* e

Version control software

Years, where available, indicate the date of first stable release. Systems with names in italics are no longer maintained or have planned end-of-life dates.

Local only|

| Free/open-source|

* RCS (1982)
* SCCS (1973)

|

Proprietary|

* The Librarian (1969)
* Panvalet (1970s)
* PVCS (1985)
* QVCS (1991)

Client–server|

| Free/open-source|

* CVS (1986, 1990 in C)
* CVSNT (1998)
* QVCS Enterprise (1998)
* Subversion (2000)

|

Proprietary|

* AccuRev SCM (2002)
* Azure DevOps
* Server (via TFVC) (2005)
* Services (via TFVC) (2014)
* ClearCase (1992)
* CMVC (1994)
* Dimensions CM (1980s)
* DSEE (1984)
* Integrity (2001)
* Perforce Helix (1995)
* SCLM (1980s?)
* Software Change Manager (1970s)
* StarTeam (1995)
* Surround SCM (2002)
* Synergy (1990)
* Team Concert (2008)
* Vault (2003)
* Visual SourceSafe (1994)

Distributed|

| Free/open-source|

* BitKeeper (2000)
* Breezy (2017)
* Code Co-op (1997)
* Darcs (2002)
* DCVS (2002)
* Fossil (2007)
* Git (2005)
* GNU arch (2001)
* GNU Bazaar (2005)
* Mercurial (2005)
* Monotone (2003)

|

Proprietary|

* Azure DevOps
* Server (via Git) (2013)
* Services (via Git) (2014)
* TeamWare (1992)
* Plastic SCM (2006)

Concepts|

* Baseline
* Branch
* Trunk
* Changeset
* Commit
* Gated
* Delta compression
* Interleaved
* File comparison
* Fork
* Merge
* Monorepo
* Repository
* Tag

* Category
* Comparison
* List

*[v]: View this template
*[t]: Discuss this template
*[e]: Edit this template