39,941 questions
1
vote
2
answers
54
views
How do I optimize a view that potentially contains thousands of views?
I have a grid/tile view implemented like below:
struct Grid: View {
let size: Int
var body: some View {
LazyVStack(spacing: 0) {
ForEach(0..<size) { _ in row }
}...
Best practices
3
votes
5
replies
139
views
Fastest way to read 10M DB rows in Python?
I’m trying to efficiently read about 10 million rows (single column) from a database table in Python and I’m not sure if my current approach is reasonable or if I’m missing some optimizations.
...
0
votes
0
answers
50
views
Optimization Challenge in Hugging Face: Effcienntly Serving Muliple, Differently Sized LLMs on a Single Gpu with PyTorch [closed]
I am currently working on a Python based Gen AI project that requires the efficient deployment and serving of multiple LLMs specifically models with different parameter counts ( Llama-2 7B and Mistral ...
-3
votes
0
answers
58
views
Can we solve the following optimization problem by dynamic programming [closed]
Suppose we have an 𝑚*𝑛 grid, let 𝑖=0,...,𝑚−1 and 𝑗=0,...,𝑛−1. For each grid point we have an array 𝑆𝑖𝑗 of size 𝑁 that serves as local score function. We want to to find a way that assigns ...
Best practices
3
votes
4
replies
146
views
Will std::is_trivially_copyable_v be deprecated by std::is_trivially_relocatable_v since C++26?
The main use of std::is_trivially_copyable_v[1] is to determine if an object array copy/move can be safely and efficiently replaced by std::memcpy.
However, C++26 introduces std::...
Advice
1
vote
14
replies
250
views
Ordered array vs. hash map in c++ (100 elements)
I need help regarding a code I want to write in c++.
I want to develop a program that receives and visualizes CAN messages on a GUI. The messages in question are about 100 distinct ID's, so we're not ...
Best practices
1
vote
2
replies
102
views
Loading a byte: Partial register stall for intel cpus (r8 vs r64)
My assembly program reads characters in a text file by loading them one by one in register 'al'. However I sometime need to use rax fully, and I think this causes a partial register stall. Now I think ...
1
vote
1
answer
75
views
Remove Cast on int fields on directQuery to 2 billion row fact when computing averages
Using Power BI directQuery to databricks SQL warehouse, I see the queries getting generated to compute an average have
SELECT
SUM(CAST(int_field AS DOUBLE)), COUNT(int_field)
FROM
fact
...
4459
votes
56
answers
2.5m
views
Which "href" value should I use for JavaScript links, "#" or "javascript:void(0)"?
The following are two methods of building a link that has the sole purpose of running JavaScript code. Which is better, in terms of functionality, page load speed, validation purposes, etc.?
...
Best practices
0
votes
3
replies
58
views
Compare fingerprints with a set of 10*10^6 other audio fingerprints in postgres
So I have a function that I used to compare audio fingerprints with a few thousand audio fingerprints stored in a postgresql. What I did basically was:
def my_function(cur: Cursor, threshold: ...
4
votes
1
answer
263
views
Why is Eigen C++ int matrix multiplication 10x slower than float multiplication (even slower than naive n^3 algorithm) when compiled with AVX512
I'm testing int matrix multiplication, but I found that it's extremely slow everywhere (python numpy using BLAS backend is also just as slow). Int matmul being slower than float matmul is ...
1
vote
0
answers
58
views
Why does CVXPY keep failing in solving problems and remain feasible?
This is a convex problem and also conforms to the syntax rules of CVXPY. I have tried changing the solver (ECOS or SCS) and adjusting the experimental parameters, but all failed.
I'm using the CVXPY ...
6
votes
0
answers
144
views
Optimized Assembly Generation for Unsigned Multiplication Leads to Unexpected Result for Cortex-M0+
I was experimenting with some fixed-point arithmetic on the Cortex-M0+ in Godbolt's compiler explorer and came across an interesting behaviour with respect to the optimisation of a multiplication ...
Advice
1
vote
5
replies
90
views
How to align a byte array transferred from Blazor to Typescript via interop to a multiple of 2 bytes?
[EDIT] Updated this question with actual working code.
(Note: This discussion talks about the way that the array interop works, which might be relevant.)
I'm trying to transfer an array of shorts to ...
1
vote
0
answers
59
views
Vue/Nuxt app loads slowly on client side -- how can I identify and fix performance issues?
I’m working on a Vue/Nuxt project where my client reports that the website is slow — especially when loading a selection window and when fetching JSON data.
However, the slowness is not very ...
4
votes
1
answer
109
views
Did MS-DOS software rely on memory offset wrapping, in practice?
With the Intel 8088's segment:offset model, code and data reads will stay in the active segment unless the segment is changed. For example, take this instruction:
ABCD:FFFF ADD AL,12
This ADD ...
2
votes
0
answers
47
views
Why does a DELETE with a JOIN on partitioned columns in BigQuery cost more than dropping specific partitions?
I have a large BigQuery table, big_table, around 5 TB in size.
It is partitioned by the column partition_date, which has about 2000 distinct values.
I also have a smaller table, small_table, which ...
1753
votes
34
answers
947k
views
How do I profile a Python script?
Project Euler and other coding contests often have a maximum time to run or people boast of how fast their particular solution runs. With Python, sometimes the approaches are somewhat kludgey - i.e., ...
1
vote
3
answers
109
views
How to check search time limits efficiently in a C++ UCI chess engine?
I’m writing a chess engine in C++ that communicates via the UCI protocol, and I need an efficient way to check whether the allocated search time has been exceeded without adding too much overhead. The ...
1616
votes
37
answers
335k
views
Fastest way to determine if an integer's square root is an integer
I'm looking for the fastest way to determine if a long value is a perfect square (i.e. its square root is another integer):
I've done it the easy way, by using the built-in Math.sqrt()
function, but ...
3413
votes
13
answers
523k
views
Improve INSERT-per-second performance of SQLite
Optimizing SQLite is tricky. Bulk-insert performance of a C application can vary from 85 inserts per second to over 96,000 inserts per second!
Background: We are using SQLite as part of a desktop ...
958
votes
11
answers
188k
views
Why does C++ code for testing the Collatz conjecture run faster than hand-written assembly?
I wrote these two solutions for Project Euler Q14, in assembly and in C++. They implement identical brute force approach for testing the Collatz conjecture. The assembly solution was assembled with:
...
3
votes
3
answers
261
views
Does trivially copyable imply trivially relocatable?
C++26 will introduce std::is_trivially_relocatable_v, and the proposal author states: Trivially copyable implies trivially relocatable.
However, I think the statement might not always be true, ...
4
votes
1
answer
137
views
Is it possible to have GCC inline vectorized trig functions?
Cosine and sine are computed with Horner's method and a Chebyshev polynomial, e.g. a0 + x(a1 + x(a2 + ...))). The fused-multiply add instructions this generates form a dependency chain, meaning we can ...
1
vote
1
answer
107
views
Hard reset gekko model to initial state
I am working on a simulation tool for a certain heat exchange system. I first design the system using a certain routine, and then assess it's off-design performance. For the off-design performance I ...
570
votes
55
answers
220k
views
Flatten an irregular (arbitrarily nested) list of lists
Yes, I know this subject has been covered before:
Python idiom to chain (flatten) an infinite iterable of finite iterables?
Flattening a shallow list in Python
Comprehension for flattening a sequence ...
0
votes
2
answers
146
views
How do gcc optimisations work under the hood?
This problem arose while I was writing a program to retrieve file sizes. I wanted to learn more about file management and other file related things, so I wrote a c++ program using the fstream and ...
985
votes
24
answers
563k
views
how do *you* calculate/approximate Big O?
Most people with a degree in CS know what Big O stands for.
It helps us to measure how well an algorithm scales.
How do you calculate or approximate the complexity of your algorithms?
14
votes
3
answers
1k
views
Efficient extraction of first/only key in a dictionary
Assumption is that we have a dictionary containing exactly one key/value pair. Objective is to extract the only key.
I can think of four ways to do this (there may be more).
import timeit
def func1(d):...
2
votes
1
answer
94
views
implicit function fit, linear regression with x and y std
In order to solve a weigthed linear regression (with x and y weights), I converted the explicit to implicit expression.
We are given (xmean,xstd) , (ymean,ystd) each 1d of length n.
The error is given ...
717
votes
40
answers
281k
views
How to iterate over a list in chunks
I have a Python script which takes as input a list of integers, which I need to work with four integers at a time. Unfortunately, I don't have control of the input, or I'd have it passed in as a list ...
5
votes
1
answer
257
views
"Repacking" 64 to 40 bits in AVX2
I have an array of 64-bit words, which I need to compact by removing the most significant 24 bits of each 64-bit word. Essentially this code in pure C:
void repack1(uint8_t* out, uint64_t* in) {
...
-2
votes
2
answers
147
views
Split N people in X constrained groups with Google Sheets
[EDIT]
Hi everyone,
I am looking for clues to work out a sorting formula with Sheets.
We are planning "teambuilding" school trips at our international college. I need to split a list of 200+ ...
-3
votes
1
answer
98
views
How does Google Fonts browser optimize their font preview experience? [closed]
Analysis of Google Fonts
Here is me scrolling through the Greek fonts
As you scroll, you'll see it progressively calls the css2 url like:
https://fonts.googleapis.com/css2?family=STIX%20Two%20Text%...
644
votes
34
answers
95k
views
Performance optimization strategies of last resort [closed]
There are plenty of performance questions on this site already, but it occurs to me that almost all are very problem-specific and fairly narrow. And almost all repeat the advice to avoid premature ...
1
vote
1
answer
116
views
How can I optimize my C# code for capturing a window to use as a texture in Godot?
Cobbling together code from various sources online I was able to create the following function that allows me to capture an image of a window on my desktop (Using Windows 11). I'm attempting to use ...
0
votes
1
answer
222
views
Efficiency difference between different ways of finding min & max in a Java list
I've found questions similar to this one, such as this but I haven't found one answering this exact question. I have a list of numbers and I want to iterate through them to find the minimum and ...
25
votes
3
answers
1k
views
Why are polymorphic objects not trivially relocatable?
Throughout the battle of P1144 vs P2786 to introduce trivial relocation optimisation for C++, one of the points P1144 has raised against P2786 is that polymorphic objects should not be trivially ...
0
votes
1
answer
48
views
Get Dual Bound of a QP with CPlex
When one wants to solve a convex Quadratic Problem in Cplex with a given time limit, how is it possible to get lower and upper bounds on the actual optimal value ?
The primal and dual objective value ...
0
votes
1
answer
53
views
Wordpress hook that runs in the last and can help to find and control all registered and enqueued scripts
I need to find and dequeue script and style files from frontend of Wordpress single post, I need a robust and full proof hook which can find out all scripts which are loading on front end of the page, ...
0
votes
0
answers
101
views
Optimizing a HTML/XML regular expression
I wish to remove part of an HTML email by regex-matching a start tag (<table>) and its respective end tag (</table>), and anchor them by specifying a unique string which must be positioned ...
-2
votes
2
answers
261
views
Is there a better way to keep ids in a vector sequential in C++?
I have a simple C++ program that manages as a todo list. The Todo, class contains a vector of Item to track each todo action and their id. The key constraint is that the ids must be kept strictly ...
678
votes
32
answers
690k
views
How do you compare float and double while accounting for precision loss?
What would be the most efficient way to compare two double or two float values?
Simply doing this is not correct:
bool CompareDoubles1 (double A, double B)
{
return A == B;
}
But something like:
...
3
votes
2
answers
276
views
Why is manual (-ish) computation of log-sum-exp faster than NumPy/SciPy functions?
I’m working with a very large array and was surprised to find that manually computing the log of the sum of exponentials is actually faster than using the built-in functions for this task from SciPy (...
0
votes
1
answer
68
views
manage Z-Order with Predictive Optimization in databricks
I want to understand how to manage Z-Order in Databricks when using Predictive Optimization (PO). According to the documentation:
"OPTIMIZE does not run ZORDER when executed with predictive ...
-1
votes
2
answers
86
views
Optimizing ps1 Script that deletes files/folders [closed]
I have here code that recusively deletes all files/folder older than 7 days within a directory. The directory is fairly large last time I ran it took about 12 hours to finish. I know that getting ...
3
votes
1
answer
182
views
What is the fastest way to evaluate a cubic given 4 packed double coefficients in a YMM register?
I have a YMM register containing 4 packed double coefficients.
I want to compute the cubic equation that they represent as quickly as possible using SSE and AVX2 intrinsics. Throughput is most ...
402
votes
44
answers
292k
views
Fastest way to list all primes below N
This is the best algorithm I could come up.
def get_primes(n):
numbers = set(range(n, 1, -1))
primes = []
while numbers:
p = numbers.pop()
primes.append(p)
numbers....
1409
votes
8
answers
824k
views
What is the purpose of the "role" attribute in HTML?
I keep seeing role attributes in some people's work. I use it too, but I'm not sure about its effect.
For example:
<header id="header" role="banner">
Header stuff in here
...
2
votes
0
answers
115
views
JIRA Lexorank in depth
I'm researching about maintaining order in a list like JIRA, and I come across Jira Lexorank. I've already understood it's core concept, but there are 2 questions that I struggle to find the in depth ...