Skip to content
Sign upLog in
← Back to Community

Make Replit DB 30x-50x Faster on Nodejs with just One Line

Profile icon
piemaddHacker

The Line Change:

Replace require('@replit/database') with require('better-replit-db') in your JS file.

How/Why it Works

I recently decided to fork the Replit DB client to add a feature which I thought would greatly improve it: a memcache.

The idea is that instead of every read and write being a get/post request to the actual database, everything is done through a dictionary stored in ram. To then make sure data persists, every write also writes to the DB, but asynchronously. This allows for the program to continue on without having to wait for the request to resolve, therefore increasing speed.

Don't believe me that this helps? Check out these speed results: (20 Operations of Each)
speed test results

Any recommendations for what I should add, let me know!

P.S. I plan on adding the same feature set to forks of other Replit DB libraries.

Voters
Profile icon
IroncladDev
Profile icon
RyanKeeler
Profile icon
MystPi
Profile icon
Highwayman
Profile icon
MattDESTROYER
Profile icon
MattBays24
Profile icon
9pfs
Profile icon
maxina
Profile icon
figglediggle
Profile icon
JBloves27
Comments
hotnewtop
Profile icon
SixBeeps

I'm surprised ReplDB entries aren't already cached. Good on ya for doing that.

Profile icon
piemadd

@SixBeeps
thanks lad, i appreciate the feeback

yours faithfully,
pero madini

Profile icon
SixBeeps

@piemadd
🥺👉👈💕

Profile icon
ch1ck3n

nice

perhaps do this in python too?

Profile icon
piemadd

@ch1ck3n
planning on it

Profile icon
ch1ck3n

@piemadd
oh, you're planning it. i want you to make it, not plan it.

Profile icon
piemadd
Profile icon
ch1ck3n
Profile icon
[deleted]

The .NET languages (C#, F#, VB) at any [email protected]

class Program{ static void Main(string[]args){ System.Console.WriteLine("I hope."); } }
Profile icon
UCYT5040

@piemadd
hurry up i need python

Profile icon
ch1ck3n

@UCYT5040
yea peero i ned python 😭😭😭

the empty void in my heart can only be filled with you (r python program)

Profile icon
figglediggle

oh hi piero

Profile icon
tussiez

This is a great idea. I think this would be especially useful in applications that need to write data that must be read immediately - such as shared data, reducing the error rate.

Profile icon
IWasAllen

Every time I start my program, the data goes null.

const db = require("better-replit-db") db.set("key1", 256) console.log(db.list()) // Output: ["key1"]

After restarting and removing the set function:

const db = require("better-replit-db") console.log(db.list()) /// Output: []
Profile icon
QuickV

poggers

hopefully this is used xD.
Profile icon
ruiwenge2

wow!

Profile icon
ruiwenge2

also another thing, at the first line of the post it said require('better-replit-database'), but in the code it said require("better-replit-db")

so maybe change that

Profile icon
piemadd

oh whoops

Profile icon
IMayBeMe

Fantastic! Repl db always was a bit slow so it’s great to see speed increases.

Profile icon
9pfs

Great job!