this post was submitted on 11 Aug 2023
221 points (98.3% liked)

Fediverse

28216 readers
123 users here now

A community to talk about the Fediverse and all it's related services using ActivityPub (Mastodon, Lemmy, KBin, etc).

If you wanted to get help with moderating your own community then head over to !moderators@lemmy.world!

Rules

Learn more at these websites: Join The Fediverse Wiki, Fediverse.info, Wikipedia Page, The Federation Info (Stats), FediDB (Stats), Sub Rehab (Reddit Migration), Search Lemmy

founded 1 year ago
MODERATORS
 
you are viewing a single comment's thread
view the rest of the comments
[–] PeleSpirit@lemmy.world 2 points 1 year ago (7 children)

I'm sorry, I'm not really understanding since I'm not techy. Are you saying it counts how many are added or removed, not the total amount? I don't understand the difference or why that would be easier to pull info from.

[–] athlon@lemm.ee 4 points 1 year ago (4 children)

Getting the total number of all comments may be very resource heavy if there is a lot of comments.

If it's just 5 comments, then the computer can quickly get them all from database and count how many of them are there. Now imagine if there is 50 000 comments and suddenly, you me and entire website ask "how many comments are there for this post?"

Suddenly the computer is overwhelmed by the request and you may end up crashing it due to amount of tasks it has to do.

It's way faster if instead of all of that, the computer kept track of a number of all comments and simply adjust it when comment is added or removed. It does not have to get all the comments and count how many are there, just simply return the number and you are done.

But in the essence, you sacriface potential accuracy for speed. You may accidentally "desynchronize" the counter - if an user requests a removal of the same comment twice, and you don't check if that comment was not removed. Or, in theory, if two separate users add or remove a comment at the same time. This is called "race condition", which is common in multi-threaded computing.

[–] PeleSpirit@lemmy.world 1 points 1 year ago (3 children)

Okay, is it because I haven't had my coffee yet?

First line:

Getting the total number of all comments may be very resource heavy if there is a lot of comments.

Fourth paragraph:

It’s way faster if instead of all of that, the computer kept track of a number of all comments and simply adjust it when comment is added or removed. It does not have to get all the comments and count how many are there, just simply return the number and you are done.

What is the difference between the bolded parts?

[–] athlon@lemm.ee 3 points 1 year ago (1 children)

First method does not store the number itself anywhere. Let's assume that you store apples. I come and ask you "How many apples do you have?". To answer, you go and count every single apple one by one and return me the number. It's very easy if you have a small number of apples, but if you have, let's say, 5000 apples - you can see how long it may take.

Second option is you keeping a track of how many apples you have in stock by having it written down somewhere. If I ask you "How many apples do you have?" you just pull out your notepad and tell me the number. If you give me an apple, you just adjust the number you have written down already.

[–] PeleSpirit@lemmy.world 1 points 1 year ago* (last edited 1 year ago) (1 children)

Okay, I swear I almost have it. Where does the stock number come from? Does it regularly pull a number instead of counting, is that the difference? I think what you're saying is, instead of it checking live, it has a total number taken every so often. Yes?

Edit: Okay I get it, except for where my initial count comes from. I guess it starts at 0?

  • First way, constantly checking the number of comments and just goes off of that.
  • Second way, stores the number 0 at first and then only updates when a comment is added or removed.

Am I ready for my certificate yet? Yikes. Thanks for going slow, lol.

[–] athlon@lemm.ee 3 points 1 year ago

No, you just update the number whenever you make any changes to how many apples you have.

load more comments (1 replies)
load more comments (1 replies)
load more comments (3 replies)