Skip to content

Instantly share code, notes, and snippets.

View simonhf's full-sized avatar

Simon Hardy-Francis simonhf

View GitHub Profile

Experiments with libarchive read blocking: Part 3

  • Note: This is a continuation from Part 2 [1].

[1] Experiments with libarchive read blocking: Part 2

What if we used coroutines to swap between different libarchive instances in the same thread?

  • Possible advantage: We might not need to modify libarchive itself!

Experiments with libarchive read blocking: Part 2

  • Note: This is a continuation from Part 1 [1].

[1] Experiments with libarchive read blocking: Part 1

How to comprehend libarchive internally?

There are too many files and lines of code (LOC) to start reading file by file

Experiments with gcc auto instrumentration of C/C++ source code for run-time function call tree tracing

What are we trying to do?

Imagine a simple C project. Here is a very small one as an example:

#include <stdio.h>

extern int bar(int a);
@simonhf
simonhf / _libarchive-read-blocking.md
Last active October 28, 2023 05:30
Experiments with libarchive read blocking: Part 1

Experiments with libarchive read blocking: Part 1

Disclaimer: Don't know much about libarchive... yet!

Step 1: Describe the issue

  • When reading a streamed archive using archive_read_open() [1] and archive_read_extract() [2] then a callback is called one or more times to read chunks of the archive.
  • This creates an issue if (a) your program needs to wait for the next chunk to arrive, and/or (b) you want to process multiple archive streams in the same thread.
  • Effectively archive_read_open() [1] and archive_read_extract() [2] block until all the necessary number of archive stream chunks have been read via the callback.
@simonhf
simonhf / rover.pl
Created October 10, 2019 19:33
You’re part of the team that explores Mars by sending remotely controlled vehicles to the surface of the planet. Develop an interface that translates the commands sent from earth to instructions that are understood by the rover.
use strict;
# Your Task
# You’re part of the team that explores Mars by sending remotely controlled vehicles to the surface of the planet. Develop an interface that translates the commands sent from earth to instructions that are understood by the rover.
# Requirements
# You are given the initial starting point (x,y) of a rover and the direction (N,S,E,W) it is facing.
# The rover receives a character array of commands as a string, for example "fffrfbrflb".
# Implement commands that move the rover forward/backward (f,b).
# Implement commands that turn the rover left/right (l,r).

Example comparison of C Pointers versus Array Indexing

Why this example comparison?

Often using C array indexing has benefits over using pointers:

  • Can be the same speed or faster code. Compiler does a good job.
  • Code easier to comprehend.
  • Log / instrumentation easier to comprehend.
  • Special debug log / instrumentation easier to write and comprehend.

Performance experiment showing overhead of locking versus shared nothing architecture

How the experiement was performed

  • Rent a packet.com m1.xlarge.x86 box which is an Intel Xeon E5-2650 V4 (2x) with 24 Cores @ 2.2 Ghz at $1.70/hr.
  • On the box run the SHF performance test in various combinations using 100 million key values.
  • The SHF performance test can be compiled with or without spin locks, in order to test the spin lock over head.
  • Obviously when compiled without spin locks, concurrent access is not possible.
  • However, when compiled without spin locks, multiple single CPU, non-concurrent instances can run in parallel AKA 'shared nothing'.
  • E.g. comparing 12 CPUs running SHF with locks versus 12 CPUs running individual shared nothing, single CPU SHF instances, reveals the overhead of not using shared nothing.
@simonhf
simonhf / _golang_tftpd.md
Last active September 9, 2019 04:28
Performance experiments with Golang, epoll, C, and tftp protocol

Time-boxed (AKA over the weekend) investigation into creating a Golang tftpd server

Disclaimer 1: Don't know much about tftp protocol.

Disclaimer 2: Don't know much about Golang.

Step 1: Learn about tftp protocol

Read up on the tftp protocol

@simonhf
simonhf / _C_vs_Golang.md
Last active July 26, 2019 22:13
C vs Golang in the context of run time performance considering compile time optimization ability with constant folding for debugging

Let's say you know C and are thinking about learning Golang. Let's also say that you prefer not to use a debugger [1]. This probably means you need to create a debug version of your Golang code. A way to do that is with constant folding [2], for example:

const constDebug = 0

if (1 == constDebug) { debugCode() } // if() compiled away due to constant folding
@simonhf
simonhf / Chain.java
Last active October 4, 2022 16:18
C versus CPP versus Java; the performance failings of naive OO
//package com.dnene.josephus;
// $ javac Person.java Chain.java && java Chain
public class Chain
{
private Person first = null;
public Chain(int size)
{