Processing math: 100%

The Book of Gehn

I found 7 posts.


Lessons Learnt Optimizing Pyte

Tags: python, pyte, terminal, optimization, performance

July 17, 2022

Few thoughts about Python code optimization and benchmarking for pyte and summarized here.


Sparse Aware Optimizations for Terminal Emulator Pyte

Tags: python, pyte, byexample, optimization, performance

July 15, 2022

byexample is a tool that reads snippets of code from your documentation, executes them and compares the obtained results with the expected ones, from your docs too.

If a mismatch happen we say that the example in your documentation failed that could mean one of two things:

  • your code (the snippet) does not do what you expect so it has a bug
  • or the code does exactly what it is supposed but you forgot to update your doc.

Very useful for testing and keep your docs in sync!

But byexample does not really execute anything by itself. Having to code an interpreter for Ruby, Java, C++ and others would be insane.

Instead, byexample sends the snippets of code toa standard interpreter like IRB for Ruby or cling for C++.

Interpreting the output from they is not always trivial.

When a interpreter prints to the terminal, it may write special escape/control sequences, invisible to human eyes, but interpreted by the terminal.

That’s how IRB can tell your terminal to output something with reds and blues colors.

That’s how byexample’s +term=ansi is implemented.

byexample has no idea of what the hell those control sequences are and relays on a terminal emulator: pyte

byexample sends the snippets to the correct interpreter and its output feeds pyte.Screen. It is the plain text from the emulated terminal what byexample uses to compare with the expected output from the example.

But pyte may take seconds to process a single output so byexample never enabled it by default.

This post describes the why and how of the optimizations contributed to pyte to go from seconds to microseconds.


TL;DR Screen Optimizations Results for Terminal Emulator Pyte

Tags: python, pyte, byexample, optimization, performance, tldr, tl;dr

July 14, 2022

This post describes to some level of detail all the performance boosts and speedups due the optimizations contributed to pyte and summarized here

For large geometries (240x800, 2400x8000), Screen.display runs orders of magnitud faster and consumes between 1.10 and 50.0 times less memory.

For smaller geometries the minimum improvement was of 2 times faster.

Stream.feed is now between 1.10 and 7.30 times faster and if Screen is tuned, the speedup is between 1.14 and 12.0.

For memory usage, Stream.feed is between 1.10 and 17.0 times lighter and up to 44.0 times lighter if Screen is tuned.

Screen.reset is between 1.10 and 1.50 slower but several cases improve if the Screen is tuned (but not all).

However there are a few regressions, most of them small but some up to 4 times.

At the moment of writing this post, the PR is still pending to review.


Planning Space Missions with Z3

Tags: z3, smt, sat, solver, integer linear optimization

May 2, 2021

A space company is planning the next 4 years. It has several projects, each one with its own budget requirement per year, but the company has a limited budget to invest.

Moreover, some projects depends on others to make them feasible and some projects cannot be done if other projects due unbreakable restrictions.

Project 1st 2nd 3rd 4th Depends Not Profit
1 Cube-1 nano-sat 1.1 2 12
2 Cube-2 nano-sat 2.5 2 12
3 Infrared sat 1 4.1 on 6 with 4 18
4 Colored img sat 2 8 with 3 15
5 Mars probe 2 8 4.4 on 1 & 2 12
6 Microwave tech 4 2.3 2 1

Under an incredible amount of assumptions and good luck, what is the best strategy to maximize the profit?


Blending Whisky with Z3

Tags: z3, smt, sat, solver, linear optimization, blending

April 29, 2021

A whisky producer uses three kind of licor to make their whisky: A, B and C.

Three kind of whisky can be made using the licor in the following proportions:

Whisky Sales Price Recipe
E 680 No less than 60% of A, no more than 20% of C
F 570 No less than 15% of A, no more than 80% of C
G 450 No more than 50% of C

The producer has the following stock and price list from its licor supplier:

Licor Stock Price
A 2000 700
B 2500 500
C 1200 400

Note: the prices are in $ per liter and the stock are in liters.

The goal is to maximize the profit.


Optimum Packaging of Chocolate

Tags: z3, smt, sat, solver, linear optimization

April 27, 2021

A small business sells two types of chocolate packs: A and B.

The pack A has 300 grams of bittersweet chocolate, 500 grams of chocolate with walnuts and 200 grams of white chocolate.

The pack B has 400 grams of bittersweet chocolate, 200 grams of chocolate with walnuts and 400 grams of white chocolate.

The pack A has a price of 120$ while the pack B has a price of 90$.

Let’s assume that this small business has for today 100 kilograms of bittersweet chocolate, 120 kilograms of chocolate with walnuts and 100 kilograms of while chocolate.

How many packs of A and B type should be packed to maximize the profits?


Compiler Optimizations under a Race Condition

Tags: reversing, IDA, performance, volatile

February 7, 2020

When two or more concurrent tasks perform non-atomic read/write operations over the same data we have a race condition and the system will be in an undefined state.

But what exactly does that suppose to mean? What is behind the generic undefined state?

- Martin Di Paola