compiler VS preemptible-thread

Compare compiler vs preemptible-thread and see what are their differences.

compiler

an incomplete toy barebones compiler backend for amd64 x86_64 in Python and an incomplete JIT compiler written in C (by samsquire)

preemptible-thread

How to preempt threads in user space (by samsquire)
Our great sponsors
  • InfluxDB - Power Real-Time Data Analytics at Scale
  • WorkOS - The modern identity platform for B2B SaaS
  • SaaSHub - Software Alternatives and Reviews
compiler preemptible-thread
15 16
20 23
- -
8.1 5.1
4 months ago 3 months ago
C C
- -
The number of mentions indicates the total number of mentions that we've tracked plus the number of user suggested alternatives.
Stars - the number of stars that a project has on GitHub. Growth - month over month growth in stars.
Activity is a relative number indicating how actively a project is being developed. Recent commits have higher weight than older ones.
For example, an activity of 9.0 indicates that a project is amongst the top 10% of the most actively developed projects that we are tracking.

compiler

Posts with mentions or reviews of compiler. We have used some of these posts to build our list of alternatives and similar projects. The last one was on 2023-12-26.
  • A copy-and-patch JIT compiler for CPython
    4 projects | news.ycombinator.com | 26 Dec 2023
    Wow! Thank you for your hard work. I use python for all experimental work so this would speed up my scripting work, such as processing data from API calls or filesystem.

    I wrote a simple toy JIT for a Javascript-like language. It might be useful for others to learn from because it's so simply written and not complicated. I do lazy patching of callsites, I haven't got anywhere near as advanced as tracing or copy-and-patching. Much of the code I wrote for this JIT was written in Python and ported to C. The Java Virtual Machine has a template interpreter which is interesting to research.

    I haven't got around to encoding amd64 x86_64 instructions as bitmasks yet, so I've hardcoded it.

    [1]: https://github.com/samsquire/compiler

  • The path to implementing a programming language
    1 project | news.ycombinator.com | 18 Jul 2023
    Thank you for this article.

    I'm a beginner to programming language implementation and design but here's what I learned. But what I want to do this with this comment I want to encourage you to start work on your programming language and just "Do Something©", Anything! You might have always dreamed to create a programming language. You can indeed try that! Have faith that you can do something, even if it's simple or incomplete, at least you learned something and got another skill.

    I don't want to be trapped by the idea that building your own programming language is impossibly difficult and that it will never be used so what's the point.

    It's so worthwhile.

    You can still do something! Effort doesn't have to be wasted! Go and try write a simple virtual machine: it's just a for loop over instructions that manipulate memory. I wrote a non-bytecode compiler, which just uses List for instructions and HashMap for instruction arguments.

    Andrew Kling built a browser and operating system and Terry Davis built an operating system. They encourage that someone can in fact learn a lot and do a lot.

    I don't want to endlessy design things OR only write implementations. I think you can write lots of ideas down AND spend time implementing things and getting your keyboard busy.

    I wrote this incomplete JIT compiler in C which has a simple nondesigned frontend that resembles Javascript. ANF is my intermediate representation.

    https://github.com/samsquire/compiler

    I wrote a multithreaded imaginary assembly language that sends integers between threads through mailboxes but nowhere near LMAX Disruptor performance.

    I think you should avoid spending too much time on your parser or lexer, use the Kaledeiscope LLVM tutorial to learn how to write recursive descent parsers and move onto code generation. I did mine with switch statements. The more you actually write parsers the easier it gets, but at first when you have no clue, you CAN just read someone else's implementation of it. Understand it, then write your own to your own design. if you get Analysis paralysis and worry about making a mistake or unoptimal decision and that prevents you from doing something suboptimal but actually do something.

    I rushed through my compiler to get to the code generation step because my goal was code generation.

    My dream: parallel and concurrent language that combines threads and coroutines with efficient interthread communication similar to LMAX Disruptor and allows writing of efficient pipelines that are serialisable like Temporal.io.

  • Mir: A lightweight JIT compiler project (2020)
    1 project | news.ycombinator.com | 2 Jul 2023
    Thanks for this.

    I started a basic toy JIT compiler for a language that looks similar to JavaScript. It is incomplete.

    https://github.com/samsquire/compiler

    With these kinds of projects there is a lot of work to be done and I feel it's difficult to get started reading a codebase for a JIT compiler or gcc or LLVM.

  • Building a Programming Language in Twenty-Four Hours
    2 projects | news.ycombinator.com | 5 Jun 2023
    https://github.com/samsquire/compiler

    It's a toy and incomplete but I've worked on compiling MOV and ADD instructions.

  • Let's make a Teeny Tiny compiler
    2 projects | news.ycombinator.com | 29 May 2023
    On thing you can do it implement a JIT compiler.

    Here's Martin Jacob's code to execute arbitrary memory:

    https://gist.github.com/martinjacobd/3ee56f3c7b7ce621034ec3e...

    Since your C program is already in memory, you have access to the C standard library and don't have to worry about linking or object formats :-) but you'll have to worry about parameter passing and FFI.

    My JIT compiler based on this idea is here https://github.com/samsquire/compiler but it is incomplete.

  • How to get started?
    3 projects | /r/ProgrammingLanguages | 25 Apr 2023
  • Notes on my incomplete JIT compiler
    5 projects | /r/ProgrammingLanguages | 20 Apr 2023
  • Erlang: More Optimizations in the Compiler and JIT
    4 projects | news.ycombinator.com | 19 Apr 2023
    This is interesting, thank you.

    I really should learn from BEAM and the OTP and learn Erlang. I get the feeling it's super robust and reliable and low maintenance. I wrote a userspace multithreaded scheduler which distributes N lightweight threads to M kernel threads.

    https://github.com/samsquire/preemptible-thread

    I recently wrote a JIT compiler and got lazy compilation of machine code working and I'm nowhere near beginning optimisation

    https://github.com/samsquire/compiler

    How do you write robust software, that doesn't crash when something unexpected goes on?

    I looked at sozo https://github.com/sozu-proxy/sozu

    and I'm thinking how to create something that just stays up and running regardless.

  • Is it possible to optimize this bytecode interpreter more?
    4 projects | /r/ProgrammingLanguages | 16 Apr 2023
  • How do you create a correct AST with interaction between method call and function call?
    2 projects | /r/ProgrammingLanguages | 12 Apr 2023

preemptible-thread

Posts with mentions or reviews of preemptible-thread. We have used some of these posts to build our list of alternatives and similar projects. The last one was on 2023-07-24.
  • Threads and Goroutines
    4 projects | news.ycombinator.com | 24 Jul 2023
    Thanks for this article.

    I want to combine the benefits of kernel threads with coroutines or goroutines/green threads/lightweight threads. (If anybody knows anything specifically about fibers, I'd appreciate that because I'm not familiar with them.)

    I have a lightweight thread scheduler https://github.com/samsquire/preemptible-thread which is a 1:M:N scheduler (1 scheduler thread, M kernel threads, N lightweight threads) with the lightweight threads being multiplexed on the kernel threads.

    I am working on a multithreaded architecture which I all 3 tier multithreaded architecture. It combines request parallelism with IO and CPU parallelism and intra request parallelism.

    We split kernel threads into three groups: app threads, which run lightweight threads, IO threads (liburing/epoll) and traditional CPU threadpool with work stealing.

    * The IO threads have buffers that other threads can write to to queue up data for sockets.

  • Async rust – are we doing it all wrong?
    9 projects | news.ycombinator.com | 19 Jul 2023
    How would you do control flow and scheduling and parallelism and async efficiently with this code?

    `db.save()`, `download()` are IO intensive whereas `document.query("a")` and `parse` is CPU intensive.

    I think its work diagram looks like this: https://github.com/samsquire/dream-programming-language/blob...

    I've tried to design a multithreaded architecture that is scalable which combines lightweight threads + thread pools for work + control threads for IO epoll or liburing loops:

    Here's the high level diagram:

    https://github.com/samsquire/ideas5/blob/main/NonblockingRun...

    The secret is modelling control flow as a data flow problem and having a simple but efficient scheduler.

    I wrote about schedulers here and binpacking work into time:

    https://github.com/samsquire/ideas4#196-binpacking-work-into...

    I also have a 1:M:N lightweight thread scheduler/multiplexer:

    https://github.com/samsquire/preemptible-thread

  • Coroutines for Go
    5 projects | news.ycombinator.com | 17 Jul 2023
    * I want to keep IO and CPU in flight at all times.

    I think I want this schedule:

    https://user-images.githubusercontent.com/1983701/254083968-...

    I have a toy 1:M:L 1 scheduler thread:M kernel threads:N lightweight threads lightweight scheduler in C, Rust and Java

    https://github.com/samsquire/preemptible-thread

    This lets me switch between tasks and preempt them from user space without assistance at descheduling time.

    I have a simplistic async/await state machine thread pool in Java. My scheduling algorithm is very simple.

    I want things like backpressure, circuit breakers, rate limiting, load shedding, rate adjustment, queuing.

  • Goroutines: The concurrency model we wanted all along
    2 projects | news.ycombinator.com | 7 Jul 2023
    Thanks for this article and to ingve for submitting it.

    Concurrency and async is my favourite topic. I wrote a very simple toy lightweight 1:M:N (1 scheduler:M kernel threads:N lightweight threads) thread scheduler in C, Rust and Java.

    https://github.com/samsquire/preemptible-thread

    It works on the principle that hot loops can be interrupted BY ANOTHER THREAD (the scheduler thread) on a timer, to give lightweight threads a chance to execute.

    What I think I want today though is an extremely rich process/concurrency API that resembles a stream API but for processes. For example, we should be able to create pipelines that can be paused, resumed, forked, merged, drop_while, iterate_until and whatever else would be useful.

  • Coroutines make robot code easy for high schoolers
    9 projects | news.ycombinator.com | 22 Jun 2023
    I really like this.

    Thank you for your comment and sharing.

    I have a lightweight 1:M:N runtime (1 scheduler thread, M kernel threads, N lightweight threads) which preempts by setting hot loops to the limit.

    https://github.com/samsquire/preemptible-thread (Rust, Java and C)

    How do you preempt code that is running?

  • Is Parallel Programming Hard, and, If So, What Can You Do About It? v2023.06.11a
    9 projects | news.ycombinator.com | 14 Jun 2023
    https://github.com/samsquire/ideas5/blob/main/NonblockingRun...

    The design is that we have three groupings of thread types. The application starts up some application threads which are not associated with a request, these service multiconsumer multiproducer thread safe ringbuffers in lightweight threads with a Go-erlang-like lightweight process runtime. (My simple lightweight thread runtime is https://github.com/samsquire/preemptible-thread) We also multiplex multiple network clients sockets across a set number of kernel threads which I call control threads. Their responsibility is to dispatch work to a work stealing thread pool ASAP which has its own group of threads. So we pay a thread synchronization cost ONCE per IO which is the dispatch from the control thread to a thread pool thread. (Presumably this is fast, because the thread pool threads are all looping on a submission queue)

    We split all IO and CPU tasks into two halves: submit and handle reply. I assume you can use liburing or epoll in the control threads. The same with CPU tasks and use ringbuffers to communicate between threads. We can always serve client's requests because we're never blocked on handling someone else's request. The control thread is always unblocked.

    I think this article is good regarding Python's asyncio story:

  • Zig Language Server and Cancellation
    2 projects | news.ycombinator.com | 10 Jun 2023
    I am deeply interested in the multithreading, parallelism, async and coroutine design space and I journal about it everyday in my ideas journal.

    I wrote a toy very simple 1:M kernel threads:N lightweight thread runtime in terrible Rust, C and Java.

    Hot loops use a structure for its limit and looping variable. Then to cancel the loop, you set the looping variable to the limit from a scheduling thread, cancelling the loop. This is used for process switching and scheduling but it can also be used for cancellation.

    Can create very responsive code this way, it's even possible to cancel while (true) loops by replacing them with while (!preempted) {}.

    https://github.com/samsquire/preemptible-thread

    There is potential for a race, but that can be detected and worked around.

  • Notes on my incomplete JIT compiler
    5 projects | /r/ProgrammingLanguages | 20 Apr 2023
    I also have a M:N m kernel threads to N lightweight thread userspace preemptive scheduler at https://github.com/samsquire/preemptible-thread It would be nice to schedule lightweight threads in a JIT compiler. Imagine being capable of running processes similar to BEAM and Go but with JIT.
  • Erlang: More Optimizations in the Compiler and JIT
    4 projects | news.ycombinator.com | 19 Apr 2023
    This is interesting, thank you.

    I really should learn from BEAM and the OTP and learn Erlang. I get the feeling it's super robust and reliable and low maintenance. I wrote a userspace multithreaded scheduler which distributes N lightweight threads to M kernel threads.

    https://github.com/samsquire/preemptible-thread

    I recently wrote a JIT compiler and got lazy compilation of machine code working and I'm nowhere near beginning optimisation

    https://github.com/samsquire/compiler

    How do you write robust software, that doesn't crash when something unexpected goes on?

    I looked at sozo https://github.com/sozu-proxy/sozu

    and I'm thinking how to create something that just stays up and running regardless.

  • Erlang's not about lightweight processes and message passing
    9 projects | news.ycombinator.com | 27 Jan 2023
    I wrote a preemptive 1:M:N scheduler in C, Rust and Java.

    https://github.com/samsquire/preemptible-thread

    It is a 1:M:N scheduler where there is one scheduler thread, M kernel threads and N lightweight threads. I take advantage that loop indexes can be structures and can be modified by other threads. So we can set the thread's looping variable to the limit to end the current loop and pause it and then schedule another thread.

What are some alternatives?

When comparing compiler and preemptible-thread you can also consider the following projects:

PicoBlaze_Simulator_in_JS - Simulator (more accurately: an assembler and an emulator) for Xilinx PicoBlaze, runnable in a browser.

Melang - A script language of time-sharing scheduling coroutine in single thread

epoll-server - C code for multithreaded multiplexing client socket connections across multiple threads (so its X connections per thread) uses epoll

ideas4 - An Additional 100 Ideas for Computing https://samsquire.github.io/ideas4/

eopl3 - My notes and solutions to exercises for EoPL3.

quickserv - Dangerously user-friendly web server for quick prototyping and hackathons

SVM - Simple stack-based bytecode VM implementations used in my class

blech - Blech is a language for developing reactive, real-time critical embedded software.

rust - Empowering everyone to build reliable and efficient software.

quaint-lang - An experimental statically typed procedural language with first-class resumable functions.

assembler - amd64 assembler

dream-programming-language - notes on my dream programming language