Skip to content

Commit a3c5a09

Browse files
committed
Map to less memory intensive version during calculation, slightly improves gachacalc performance on Firefox
1 parent 92335ab commit a3c5a09

1 file changed

Lines changed: 9 additions & 10 deletions

File tree

pages/tools/gachacalc.tsx

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -419,14 +419,10 @@ function calcSimsRegular(current: number, pity: number, pulls: number, guarantee
419419

420420
function calcSimsInt(starterSim: Sim, pulls: number, banner: Banner): ReducedSim[][] {
421421
console.time("calc")
422-
const sims: Sim[][] = calcSimsExact([starterSim], pulls, banner, 0)
423-
console.timeEnd("calc")
424-
425-
426-
return sims.map(sim => {
422+
const sims = calcSimsExact([starterSim], pulls, banner, 0, sims => {
427423
// Reducing to simple sims with less information
428424
const reducedSims: ReducedSim[] = []
429-
sim.forEach((sim: Sim) => {
425+
sims.forEach((sim: Sim) => {
430426
if (sim.rate == 0) return
431427

432428
const other = reducedSims[sim.const + 1]
@@ -441,10 +437,13 @@ function calcSimsInt(starterSim: Sim, pulls: number, banner: Banner): ReducedSim
441437
})
442438
return reducedSims
443439
})
440+
console.timeEnd("calc")
441+
442+
return sims
444443
}
445444

446-
function calcSimsExact(sims: Sim[], pulls: number, banner: Banner, prune = 1e-8) {
447-
const allSims: Sim[][] = [sims]
445+
function calcSimsExact<T>(sims: Sim[], pulls: number, banner: Banner, prune = 1e-8, mapper: (sims: Sim[]) => T = (sims => sims as T)): T[] {
446+
const mappedSims: T[] = [mapper(sims)]
448447
for (let i = 0; i < pulls; i++) {
449448
const newSims: Record<number, Sim> = {}
450449

@@ -534,7 +533,7 @@ function calcSimsExact(sims: Sim[], pulls: number, banner: Banner, prune = 1e-8)
534533
}
535534

536535
sims = Object.values(newSims)
537-
allSims.push(sims)
536+
mappedSims.push(mapper(sims))
538537
}
539-
return allSims
538+
return mappedSims
540539
}

0 commit comments

Comments
 (0)