Skip to content

Repository files navigation

std::embed implementation for the poor (C++17)

This repository contains an example implementation of the std::embed from the P1040 proposal. There is an overview in the blog post, feedback is highly appreciated.

Usage

To distribute arbitrary resources with your application two steps are required:

  1. Preprocess resources to create the corresponding header files.
  2. Gather resources from the source code.

Building

Use CMake to build rh::embed itself, tests and benchmark. Tests are enabled by default, use -DBYPASS_TESTS=1 to disable them, benchmark, on the other hand, is disabled. To enable benchmark build use -DENABLE_BENCHMARK=1.

Benchmark

One of the key concerns is performance. I've benchmarked two corner cases:

  1. One big file
  2. Multiple small files

As a starting point, I've measured the complete rebuild process on my PC (MSVC 17.0.4, Ryzen 3700X, 32GB of RAM) with the bare time of 1390 ms. For the sake of history and comparison, there's also data for my older PC (MSVC 15.9.2, i5-750, 12GB of RAM) with a baseline of 3992 ms.

Total rebuild times

Table for the one big file:

File sizeBuild time, ms, WSLBuild time, ms, WindowsBuild time, ms, Old PC
1 byte47914134033
8 bytes47114124423
64 bytes48213903984
512 bytes49114024197
4 KB48514134393
32 KB50314214843
256 KB70815486431
2 MB2645268811436
16 MB192341174812912

For the multiple small files:

Number of 1 KB filesBuild time, ms, WSLBuild time, ms, WindowsBuild time, ms, Old PC
147313864400
848514225200
6458715876236
5121268330923034
10242049860161523

The vast majority of the time is occupied by the link time, not the rh::embed itself.

rh::embed times

N.B. These times were measured on my old PC, they're roughly the same on my new one, so I decided to leave this part as is.

To illustrate this, I've measured both the rh::embed performance and the total part of the whole process:

File sizeEmbed time, msPercent of the whole rebuild time
1 byte591.46
8 bytes501.13
64 bytes561.4
512 bytes491.11
4 KB491.01
32 KB851.32
256 KB751.16
2 MB3122.7
16 MB179613.9
Number of 1 KB filesEmbed time, msPercent of the whole rebuild time
1521.18
8621.19
641392.22
5128443.66
102415842.5

Roadmap

  • Make the tool cross-platform (CMake)
  • Add CPack scripts for the proper installation
  • Compressing the resources
  • Use the clang AST (scan the source files for the resources)

About

std::embed implementation for the poor (C++17)

Resources

Stars

92 stars

Watchers

7 watching

Forks

Releases

Packages

Used by

Contributors

Languages