The Knapsack Problem with Hardware Intrinsics

Acknowledgements

I would like to thank Kristof for reviewing this post. He gave me great ideas to further discover the problem and to have a better understanding on AVX. Thank you, Kristof.

Introduction to the Problem

The Knapsack problem is an optimization task: given a set of items, each with a weight and a value, create a subset of these items so that their total weight is less than or equal to a given limit, and their total value is maximized.

Find out more


NDC London 2020

I have attended to NDC London 2020 conference, and collected the talks I prefer or suggest for watching on YouTube.

Find out more


Null-coalescing assignment operator ??=

The Operator

One of the new C# features is the null-coalescing assignment operator: ??=. It assigns the value of its right-hand operand to the left-hand operand if the left-hand operand is null.In other words:

if(myfield == null)
  myfield = new object();

can be replaced with

Find out more


Blazor Initializing State

Problem

Using WebAssembly based Blazor is one great technology to create static websites using C# and mono. Unfortunately search engines are not yet good enough to index WebAssembly based websites. A way to overcome this issue is to create a Host service which only does pre-render and serve the files for the static website. This way search engines can load the pre-rendered HTML page, and index that.

When the webassembly based, client side, static page is fully loaded and initialized, the same state must be re-created as the pre-rendered page had during rendering. If initiating this state includes an async operation, such as fetching data from a service, the Blazor client might finish the first render before the required data is available. Without data, the first render will render an empty page. Once the state initialized a new render will re-create the same (or similar) DOM as the pre-rendered page had. Having these 2 renders results a huge 'flash' like experience for the user, where an empty page is rendered for a moment.

Proposal

Find out more


Missing Number Performance Tests 2

A couple of weeks ago, I had a post about a tipical interview question: finding a missing number from an unordered array.

The task goes as follows:

Given an array with integers from 1 to N. The order of the integers is unknown. One of the randomly chosen number is replaced with 0. Create a method that receives the array as an input and returns the replaced number.

I am not going into the details of edge cases, input validation, error handling, etc. This post purely checks the performance aspects of some of the possible solutions. I also assume that N=x*8.

Find out more