DavideViolante / gender-detection-from-name

Gender detection from first name
MIT License
14 stars 9 forks source link

perf: improve speed execution and memory consumption #91

Closed davidwitten closed 2 months ago

davidwitten commented 2 months ago

The all map that was created by combining all language maps:

   all: new Map([...itMap, ...enMap, ...esMap, ...frMap, ...deMap]),

is very computationally intensive and much slower than calling each of the maps individually.

I kept the logic the exact same as before, and all the tests pass.

Performance impact:

Change in memory usage before/after

I tested using getGender('davide')

Now

rss: 0 MB
heapTotal: 0 MB
heapUsed: 0.00218963623046875 MB
external: 0.00003814697265625 MB
arrayBuffers: 0 MB

Before

rss: 19.171875 MB
heapTotal: 16.0625 MB
heapUsed: 8.680007934570312 MB
external: 0.00003814697265625 MB
arrayBuffers: 0 MB

This optimization significantly reduces memory usage and improves execution speed.

davidwitten commented 2 months ago

@DavideViolante

DavideViolante commented 2 months ago

Thank you for the contribution, that seems nice, I left you a comment and then I think it's ok to merge.