54

Asuming expensive_calc_one and expensive_calc_two are pure functions Unfortunately, determining whether a function is pure is equivalent to solving the Halting Problem in the general case. So, you cannot have an Ahead-of-Time compiler which can in the general case decide whether a function is pure or not. You have to help the compiler by explicitly ...


9

Compilers are not generally smart enough to do this, in particular because most languages don't have a sufficiently reliable concept of a “pure function”. There can be rather subtle interactions between threads. Clearly, they should not access the same memory regions. But the program might rely on invariants that could be broken through concurrent ...


6

The advice that the C++ standard libraries aren't slower than C code is true when the same operations are performed. A quick look at the LodePNG code shows that is loads a file like this: determine the file size allocate a buffer large enough to store the entire file read the file into the buffer in one go Based on your description, I assume you are ...


5

Does this mean the OOP paradigm is not a good fit for this category of problems? Or am I simply not experienced enough with OOP to utilize for this domain? You can use the OOP paradigm to encapsulate the algorithmic logic, i.e. define a single class that "wraps" the entire algorithm. Those global lists can be set up as member variables within the ...


4

Python does not interpret line by line. The default Python implementation (CPython) compiles the entire module to bytecode and then runs it. However, the CPython implementation does not place an emphasis on optimizations. The interpreter will do exactly what you tell it to do, which means that small changes to your code can have a big performance effect. In ...


4

You will have to measure to see if performance is an actual problem. But your intuition about query performance is wrong: I am just worried that this many cascading queries might heavily affect performance, especially as the task types grow, since with DeliveryDestination we are already at O(N³) complexity. Your intuition seems to be that a join is of O(n) ...


3

This really is an engineering problem, a common way this is handles is keeping the libraries and your own application separate, and giving out updates to your program as partial updates, allowing people to keep the library jars. In some cases, this is not possible,and a single jar needs to be used. One of the tools you can use to remove non-linked files is ...


3

SVG shapes are a collection of (mainly bezier) curves. To draw a curve from right to left, you'd need to find all the points where the curve has local maxima on the x-axis, split the curve into two at each of those points, and reverse one of the segments. Further work is required to draw each curve with the same x-velocity. While this is all possible to do ...


2

Introducing things running in parallel (not the same as concurrency, as noted in comments) is actually done quite a bit during runtime. It sounds like what you're most interested in is instruction level parallelism where two instructions are running simultaneously, finishing in half(ish) the time it would take them to run sequentially. Specifically, you're ...


2

There cannot be a generic solution that efficiently works for all functions. The only generic solution is to calculate the target function separately for each input combination. To get more efficient, you'd have to do one of the following: Exploit common sub-structures of the problem and avoid recomputing them multiple times. Ideally, this would lead to a ...


1

There cannot be an universal performance tradeoff. A web app targeted at content creators who work from a beefy gaming PC with a gigabit internet connection will settle on a very different tradeoff than a page targeted at people from developing countries who are using an outdated smartphone over a shaky mobile data connection where bandwidths are measured in ...


1

In general, there are the following two approaches for such scenarios: reduce the overall amount of data which is transferred to the client (this is what Philip Kendall suggested in the comments) make the data request asynchronous and return the results in batches or pages The first approach is most useful if you can tailor the data request directly to ...


1

I'm assuming that you're modeling a Linear Program where you want to minimize min v = |x1 - x2| s.t. 0 <= x1 <= C 0 <= x2 <= C This model is equivalent to min v s.t. x1 - x2 <= v x2 - x1 <= v v >= 0 0 <= x1 <= C 0 <= x2 <= C In general, the trick used in Linear Programming when dealing with absolute values is to introduce ...


1

Depending on your long term needs, keeping those data structures in global variables might be just right if you're using the program in isolation. As soon as you want to use the algorithm as part of another program or want to make it available to other users as part of a library, put the various data structures into instance variables of the class that ...


1

Let me guess: this is a program only for academic purposes, which will probably have a restricted life time in the range of 2K lines of code up to 20K at most with just one developer (you)? Then using the restricted "amount of OOP" you already did ("abstracting some datastructures into classes") is probably what makes sense most. You ...


1

Let's start to answer the first part of the question: There are n objects of weight w1, ..., wn. Their total weight is W=Σi=1..n wi There are k boxes, each one with a weight limit L. Your goal is to assign each object to one of the boxes, so the total weight of each box approximates M:=W/k. W/k should be ideally smaller than L, otherwise one can set M:=L. ...


1

For an outline, let us ignore ellipses and stick to lines. The laser cutter can cut lines [...] with simple instructions, as well as making jumps Let me assume you mean "straight line segments" and "polygons made of straight line segments. So my first approach is to take each segment from the SVG and translate it to a single instruction ...


1

You could optimize the loop in your example by adding a generator instead of the usual retrieval function: def get_customers() api_result = api.request('customers/get') for item in api_result: customer = Customer.fromDict(item) yield customer ... customers = get_customers() for customer in customers: process_customer(customer)...


Only top voted, non community-wiki answers of a minimum length are eligible