GithubHelp home page GithubHelp logo

hvr / rawfilepath Goto Github PK

View Code? Open in Web Editor NEW

This project forked from xtendo-org/rawfilepath

0.0 2.0 0.0 50 KB

Use RawFilePath (ByteString) instead of FilePath (String)

License: Other

Haskell 74.02% C 25.98%

rawfilepath's Introduction

rawfilepath

A Haskell library for the mid-level system functions for the RawFilePath data type.

Background

Traditional String is notorious:

  • Up to 40 bytes (five words) required for one character (the List constructor, the pointer to the Char constructor, the Char constructor, the actual Char value, and the pointer to the next List constructor)
  • Heap fragmentation causing malloc/free overhead
  • A lot of pointer chasing for reading, devastating the cache hit rate
  • A lot of pointer chasing plus a lot of heap object allocation for manipulation (appending, slicing, etc.)
  • Completely unnecessary but mandatory conversions and memory allocation when the data is sent to or received from the outside world

Transition to Text and ByteString began, but even after a dazzling community effort, FilePath, a key data type for programming anything useful, remained to be a type synonym of String.

To put a cherry on top of creaking, fuming, dragging, and littering pointers all over the heap space, String had another fantastic nature to serve as a file path data type: Encoding blindness. All functions that return FilePath would actually take a series of bytes returned by a syscall and somehow magically "decode" it into a String which is surprising because no encoding information was given. Of course there is no magic and it's an abject fail. FilePath just wouldn't work.

In June 2015, three bright Haskell programmers came up with an elegant solution called the Abstract FilePath Proposal and met an immediate thunderous applause. Inspired by this enthusiasm, they further pursued the career of professional Haskell programming and focused on more interesting things. 16 months later, a programmer under the pseudonym XT got so sick and tired of the situation and released a package called rawfilepath that, despite being far from perfect, worked.

So what is this?

RawFilePath is a data type provided by the unix package. It has no performance issues because it is ByteString which is packed. It has no encoding issues because it is ByteString which is a sequence of bytes instead of characters. However, the functions in unix are low-level, and the higher-level packages such as process and directory are strictly tied to FilePath.

So I decided to start writing the RawFilePath version of those functions.

Advantages

  • High performance
  • No round-trip encoding issue
  • Minimal dependencies (bytestring, unix, and base)
  • Lightweight library (under 400 total lines of code)
  • Available now

Documentation

API documentation of rawfilepath on Stackage.

To do

rawfilepath is in an early stage, although major backwards-incompatible changes are unlikely to happen. We can probably port more system functions that are present in process or directory

Patches will be highly appreciated.

rawfilepath's People

Contributors

xtendo-org avatar

Watchers

Herbert Valerio Riedel avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.