Learn to Code via Tutorials on Repl.it!

← Back to all posts
Make Replit DB 30x-50x Faster on Nodejs with just One Line
h
piemadd

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)

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
MattDESTROYER
MattBays24
9pfs
maxina
figglediggle
JBloves27
RayhanADev
MarcusWeinberger
SixBeeps
EpicGamer007
Comments
hotnewtop
SixBeeps

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

piemadd

@SixBeeps thanks lad, i appreciate the feeback

yours faithfully,
pero madini

SixBeeps

@piemadd 🥺👉👈💕

ch1ck3n

nice

perhaps do this in python too?

piemadd

@ch1ck3n planning on it

ch1ck3n

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

piemadd
ch1ck3n
[deleted]

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

UCYT5040

@piemadd hurry up i need python

ch1ck3n

@UCYT5040 yea peero i ned python 😭😭😭

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

figglediggle

oh hi piero

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.

QuickV

poggers

hopefully this is used xD.
ruiwenge2

wow!

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

piemadd

oh whoops

IMayBeMe

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

9pfs

Great job!