tac

tac is a high-performance, simd-accelerated, cross-platform rewrite of the GNU tac utility from Coreutils, released under a BSD-compatible (MIT) license. tac reads input from a file (or from stdin, but see below) and then prints it line-by-line backwards.

This tac implementation uses simd-acceleration for new line detection and utilizes memory-mapped files on all supported operating systems. It is additionally written in rust for maximum integrity and safety.

Who needs a faster tac anyway?

Good question. Try grepping through a multi-gigabyte web access log file in reverse chronological order (tac --line-buffered access.log | grep foo) and then get back to me.

Usage

``` Usage: tac [OPTIONS] [FILE1..] Write each FILE to standard output, last line first. Reads from stdin if FILE is - or not specified.

Options: -h --help Print this help text and exit -v --version Print version and exit. --line-buffered Always flush output after each line. ```

tac reads lines from any combination of stdin and/or zero or more files and writes the lines to the output in reverse order.

Example

$ echo -e "hello\nworld" | tac world hello

Installation

tac may be installed via cargo, the rust package manager:

cargo install tac

Help is humbly requested in getting tac into the package managers for various platforms. It's really a time-consuming task, especially for someone that only interacts with the various packaging tools once in a blue moon as opposed to on a daily basis.

Implementation Notes

This implementation of tac uses the AVX2 instruction set to provide SIMD acceleration for the detection of new lines. The usage of memory-mapped files additionally boosts performance by avoiding slowdowns caused by context switches when reading from the input if speculative execution mitigations are enabled. It is significantly (2.55x if mitigations disabled, more otherwise) faster than the version of tac that ships with GNU Coreutils, in addition to being more liberally licensed.

To obtain maximum performance:

License and Copyright

tac is written by Mahmoud Al-Qudsi <mqudsi@neosmart.net> of NeoSmart Technologies, and released under the terms of the MIT public license. Copyright NeoSmart Technologies 2021. All rights not assigned by the MIT license are reserved.