Code Monkey home page Code Monkey logo

Comments (2)

strikeentco avatar strikeentco commented on July 29, 2024 1

Hello, thank you for the question.

This library were originaly inspired by geo-proximity. geo-proximity was wonderful but I needed something, which works without DB, so I decided to port geo-proximity for work with memory only.
This library stores all data in memory, so this is good and bad at the same time. This is good because it fast, this is bad because it takes a lot of memory (depends on data size).
To minimize memory usage it's recommended to use default data syntax or use .createCompactSet method.

Unlike geo-proximity and geo-redis (which is async libs), this library is sync so it's may be sometimes bad (in the future I'll add async methods).

If data set is sorted, this library works really fast.
For example: I use geo-nearby on my site, where this library searching in file with 208000 locations.
This code is executed for 3ms:

const geo = new Geo(geoSet, { sorted: true });
geo.limit(1).nearBy(-18.96, 32.66, 100000); // limit(1)

This code is executed for 4ms:

const geo = new Geo(geoSet, { sorted: true });
geo.limit(0).nearBy(-18.96, 32.66, 100000); // no limits

This code is executed for 7ms:

const geo = new Geo(geoSet, { sorted: true });
geo.limit(1).nearBy(-18.96, 32.66, [250, 100000]); // limit(1) + a range of distances

This code is executed for 10ms:

const geo = new Geo(geoSet, { sorted: true });
geo.limit(0).nearBy(-18.96, 32.66, [250, 100000]); // no limits + a range of distances

In the examples below, it's considered the worst case, when the desired entry at the end of the file and data set is unsorted.
This code is executed for 10ms:

const geo = new Geo(geoSet);
geo.limit(1).nearBy(-18.96, 32.66, 100000); // limit(1)

This code is executed for 17ms:

const geo = new Geo(geoSet);
geo.limit(0).nearBy(-18.96, 32.66, 100000); // no limits

This code is executed for 38ms:

const geo = new Geo(geoSet);
geo.limit(1).nearBy(-18.96, 32.66, [250, 100000]); // limit(1) + a range of distances

This code is executed for 99ms:

const geo = new Geo(geoSet);
geo.limit(0).nearBy(-18.96, 32.66, [250, 100000]); // no limits + a range of distances

from geo-nearby.

jgamedev avatar jgamedev commented on July 29, 2024 1

Hey Alexey,
Thank you for you taking the time answer this so thoroughly (maybe add some of this info to the read me for others considering this package in the future?)
I suspect it would not be hard to re-structure it in a way that doesn't block the process execution.. maybe by leveraging Node's process.fork() capabilities?

Thanks again and hopefully I'll find some time to try this package in the coming days. Cheers!

from geo-nearby.

Related Issues (8)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.