What gives the performance to build and search a small social graph

Hi all,

I have more of a general development question. In terms of speed (storage) I’m trying to build and search a (small) social graph. (2 steps pf separation: known person -> friend -> friend --> 2nd known person)

_Step 1: _ Build the graph and store (once in a while refresh)

person 1 -> friends -> friends' friends

_Step 2: _ Search
see which friends of person 2 are in the friends’ friends of person 1

_Step 3: _ Show the matches

I consider two options for building / search:

Option 1:

Step 1: Small object (potential longer search?)

{'name': 'person 1', 'data': 'friend A, friend B'}
{'name': 'friend A', 'data': 'person 1, friend B, friend C'}

Step 2:
Search all ‘data’, get the ‘name’ from each match

Option 2:

Step 1 :bigger objects (potentially quicker search)

  • Index with all people
{'person 1, friend A, friend B, person 1, friend B, friend C'}
  • Object with parents of each index
{'name':'person 1', 'data':''}
{'name':'friend A', 'data':'person 1'}
{'name':'friend B', 'data':'person 1'}
{'name':'person 1', 'data':'person 1, friend A'}
{'name':'friend B', 'data':'person 1, friend A'}

Step 2:
The idea is then to search the index (probably quicker) and get the corresponding data parents pair from the Object.

Extra info:
content will be userids (only integers)

Any thoughts on search performance vs memory usage on these two different options?

thanks

Hi!

Where are you planning to store the graph? In memory as JS objects? If so, the fastest is to simply have the objects reference each other.

Basically Yes. As Js objects. Only the relations to known persons I’ll put in Observables.

Person 1 is the owner of the device so his graph I would like to store on the device as well, so it’s straight available when restarting the app.

Flow: Person 1 will get a message (request) from unknown person 2, geographically nearby. My objective is to show person 1 that person 2 is actually a friend of a friends’ friend. (further is irrelevant for now)

Anders Lassen wrote:

If so, the fastest is to simply have the objects reference each other.

What do you exactly mean with “have the objects reference each other”

What do you exactly mean with “have the objects reference each other”

Simply like this:

 var person1 = { name: "Joe", friends: [] }
 var person2 = { name: "Bob", friends: [] }
 person1.friends.push(person2);

If you want the friend relationships to be mutable, you can replace the arrays with observables.