Log of the Rewrite's Performance Improvements #49
Replies: 1 comment
-
A small but massive change.A big focus of this "rewrite" is for mainly performance, both on server-side and client-side. Currently Beatbump tends to just be a free-for-all of subpar, mostly copy + pasted from one fiile to another kind of code. To solve this, I am working on creating several helpers and utils for common pieces of code, as well as for performance and ease of use! One problem that is encompasses the whole of this comment, is on the backend side. Beatbump has a Array.map is slow for almost any larger than ~250-400 items. Beatbump found this out quickly. After months of on and off benchmarking, here's a comparison of some of the good ways of going over large Arrays/Array of ObjectsJSBench.Me. Go to the pastebin found in the JSBench's description and copy and paste the JS Object into the "Setup JS" section within JSBench. The goal is performance, standardized, and lean code. Here's what I've gotten so far for the Array module: type VoidCallback<T> = (item: T, index: number, array: Array<T>) => void;
type ItemCallback<T> = (item: T, index: number, array: Array<T>) => T;
export function find<T>(
array: Array<T>,
predicate: (item: T) => boolean
): T | undefined {
let len = array.length;
for (; len--; ) {
if (predicate(array[len])) {
return array[len];
}
}
return undefined;
}
export function findAll<T>(
array: Array<T>,
predicate: (item: T) => boolean
): T[] {
let len = array.length;
let idx = 0;
const result = [];
for (; len--; ) {
if (predicate(array[len])) {
result[idx++] = array[len];
}
}
return result;
}
export function iter<T>(array: Array<T>, cb: VoidCallback<T>): void {
const len = array.length;
let idx = -1;
for (; ++idx < len; ) {
cb(array[idx], idx, array);
}
}
export function map<T>(array: Array<T>, cb: ItemCallback<T>): T[] {
let idx = -1;
const length = array.length;
const newArray = Array(length)
for (; ++idx < length;) {
newArray[idx] = cb(array[idx], idx, array);
}
return newArray;
} This is just one example of many that will be completed in due time. PS: Beatbumps gotten significant performance gains from these. |
Beta Was this translation helpful? Give feedback.
-
Trending Page
Prior to the rewrite, the Trending Page would average 675-750ms response time on the dev server.
Current times in the rewritten version:
Artist Page
The performance wasn't too bad normally in the original version, but the code was a mess. Managed to get the times down from ~550ms average on the dev server to:
Here's the rewritten code:
More improvements to come soon, as I am aiming to do a complete rewrite essentially.
Beta Was this translation helpful? Give feedback.
All reactions