DbContext ChangeTracking kills performance?

Is the technique at the end of this documentation useful? Alternatively, I’ve avoided many of the performance pitfalls using a fluent interface to declaratively state which entities in a given transaction for sure won’t change vs. might change (immutable vs. immutable). For example, if the entities I am saving are aggregate roots in which the … Read more

e-commerce: Algorithm for calculating discounts

Assuming that: You can compute all available discounts based on your basket Each product can only have a single discount applied to it Each discount can only be used once Then the problem becomes one that is called an assignment problem and can be optimally solved in O(n^3) using the Hungarian algorithm. You will need … Read more

What does OpenJDK JMH “score error” exactly mean?

This is the margin of error for the score. In most cases, that is a half of confidence interval. Think about it as if there is a “±” sign between “Score” and “Score error”. In fact, the human-readable log will show that: Result: 1.986 ±(99.9%) 0.009 ops/ns [Average] Statistics: (min, avg, max) = (1.984, 1.986, … Read more

Why would introducing useless MOV store instructions speed up a tight loop in x86_64 assembly?

The most likely cause of the speed improvement is that: inserting a MOV shifts the subsequent instructions to different memory addresses one of those moved instructions was an important conditional branch that branch was being incorrectly predicted due to aliasing in the branch prediction table moving the branch eliminated the alias and allowed the branch … Read more

In SQLite, do prepared statements really improve performance?

Prepared statements improve performance by caching the execution plan for a query after the query optimizer has found the best plan. If the query you’re using doesn’t have a complicated plan (such as simple selects/inserts with no joins), then prepared statements won’t give you a big improvement since the optimizer will quickly find the best … Read more

Examples where compiler-optimized functional code performs better than imperative code

There are cases where the same algorithm will optimize better in a pure context. Specifically, stream fusion allows an algorithm that consists of a sequence of loops that may be of widely varying form: maps, filters, folds, unfolds, to be composed into a single loop. The equivalent optimization in a conventional imperative setting, with mutable … Read more

Linked list vs. dynamic array for implementing a stack

There are many tradeoffs involved here and I don’t think that there’s a “correct” answer to this question. If you implement the stack using a linked list with a tail pointer, then the worst-case runtime to push, pop, or peek is O(1). However, each element will have some extra overhead associated with it (namely, the … Read more

tech