New answers tagged

6 votes

C# and C++ Inheritance and Performance - Shouldn't Compilers Handle this Issue?

Investigating your underlying claim For the purpose of example, let's say that you have a codebase where there is a MyType class, and there is also some kind of base-type-oriented logic, let's say: ...
Flater's user avatar
  • 45.7k
27 votes

C# and C++ Inheritance and Performance - Shouldn't Compilers Handle this Issue?

Don't we need to take a step back here? Under the hood, it generally all boils down to simply functions being called the with the this pointer as first arg. It's good to question things from first ...
Alexander's user avatar
  • 3,842
1 vote

C# and C++ Inheritance and Performance - Shouldn't Compilers Handle this Issue?

Why can't the compiler/jitter optimize out the call resolutions at compile time? It can, you help it by marking some classes as sealed, The linter also knows that if a class is internal, and has no ...
Ewan's user avatar
  • 71k
4 votes

C# and C++ Inheritance and Performance - Shouldn't Compilers Handle this Issue?

The whole point of virtual function calls is that at compile time it is unknown which code will be executed. Swift has a partial solution: You can specify whether a class can be subclassed in a ...
gnasher729's user avatar
  • 42.7k
12 votes

C# and C++ Inheritance and Performance - Shouldn't Compilers Handle this Issue?

Imagine this extremely simple example A value = Random.Shared.Next(0, 2) == 0 ? new B() : new C(); value.M(); abstract class A { public abstract void M(); } class B : A { public override ...
Euphoric's user avatar
  • 36.9k
6 votes

C# and C++ Inheritance and Performance - Shouldn't Compilers Handle this Issue?

Why can't the compiler/jitter optimize out the call resolutions at compile time? It can in some cases, but there are reasonable scenarios that preclude compile-time identification of the proper ...
Erik Eidt's user avatar
  • 33.4k
2 votes
Accepted

How do function inlining and Tail Call Optimization affect call stack?

AFAIK every function call adds a new stack frame into a call stack. This is true for some functions, but not for all functions.  On some processors, simple functions, called leaf functions (functions ...
Erik Eidt's user avatar
  • 33.4k
0 votes
Accepted

Build an API for a graph app with + 30 millions data points

I think you might be making this a more difficult than it is. You have M data points to show on a chart. You can only actually display N data points at a time. You simply need to divide your point ...
JimmyJames's user avatar
  • 25.2k
0 votes

Build an API for a graph app with + 30 millions data points

The usual approach for allowing different zoom levels for 2D graphics is to use a tree-like data structure (for example a quadtree), or for a one-dimensional time-series just a binary tree, where you ...
Doc Brown's user avatar
  • 201k
0 votes

How can I make code that is both DRY and fast where intermediate values in a calculation may or may not be needed?

Newcomer developers have a tendency to copy/paste code and not realize that there's an opening for reusability. Intermediate developers understand the importance of reusability and apply it to ...
Flater's user avatar
  • 45.7k
14 votes
Accepted

How can I make code that is both DRY and fast where intermediate values in a calculation may or may not be needed?

I would consider the following alternatives, in that order: Start with the DRY variant, even it is less efficient. In most real-world cases, this won't matter. If a benchmark tells you here is your ...
Doc Brown's user avatar
  • 201k

Top 50 recent answers are included