Skip to content

Instantly share code, notes, and snippets.

View acefsm's full-sized avatar

acefsm acefsm

View GitHub Profile
@acefsm
acefsm / libdispatch-efficiency-tips.md
Created January 27, 2021 14:18 — forked from tclementdev/libdispatch-efficiency-tips.md
Making efficient use of the libdispatch (GCD)

libdispatch efficiency tips

The libdispatch is one of the most misused API due to the way it was presented to us when it was introduced and for many years after that, and due to the confusing documentation and API. This page is a compilation of important things to know if you're going to use this library. Many references are available at the end of this document pointing to comments from Apple's very own libdispatch maintainer (Pierre Habouzit).

My take-aways are:

  • You should create very few, long-lived, well-defined queues. These queues should be seen as execution contexts in your program (gui, background work, ...) that benefit from executing in parallel. An important thing to note is that if these queues are all active at once, you will get as many threads running. In most apps, you probably do not need to create more than 3 or 4 queues.

  • Go serial first, and as you find performance bottle necks, measure why, and if concurrency helps, apply with care, always validating under system pressure. Reuse

#include <stdatomic.h>
#include <stdint.h>
#include <stdbool.h>
/*!
An atomic ARC reference. Here's how it works:
The lowest bit of the pointer (mask 0x1) is used as a tag for the pointer being stored.
if the tag bit is set, that means that one thread currently owns this pointer, and will release it if the value has
been concurrently updated.
@acefsm
acefsm / BNRTimeBlock.h
Created May 15, 2018 23:25 — forked from bignerdranch/BNRTimeBlock.h
Timing Utility Post 20120308
CGFloat BNRTimeBlock (void (^block)(void));
@acefsm
acefsm / SpinlockTestTests.swift
Created May 12, 2018 00:21 — forked from steipete/SpinlockTestTests.swift
Updated for Xcode 8, Swift 3; added os_unfair_lock
//
// SpinlockTestTests.swift
// SpinlockTestTests
//
// Created by Peter Steinberger on 04/10/2016.
// Copyright © 2016 PSPDFKit GmbH. All rights reserved.
//
import XCTest
@acefsm
acefsm / queues.md
Created February 6, 2018 19:26 — forked from weibel/queues.md
iOS persistent queue implementations

Persistent queues are really useful. I have envied Android developers for having the Tape queue http://square.github.io/tape/ and the Android Priority Jobqueue https://github.com/yigit/android-priority-jobqueue

Below I have compiled a list of the persistent queue implementations for iOS that I know of. Most of them are not in active development. Ping me if you want a library added to the list.

@acefsm
acefsm / introrx.md
Created November 10, 2017 14:07 — forked from staltz/introrx.md
The introduction to Reactive Programming you've been missing
@acefsm
acefsm / HUnorderedMap.hh
Created November 11, 2016 11:53 — forked from rsms/HUnorderedMap.hh
Testing (lookup) performance of different hash map algorithms for constant keys (pointer is hash)
#ifndef H_UNORDERED_MAP_
#define H_UNORDERED_MAP_
#import <tr1/unordered_map>
template<class K, class T>
class HUnorderedMap {
public:
typedef typename std::tr1::unordered_map<K, T > Map;
typedef typename Map::value_type ValueType;