FindFirstChildOfClass behavior vs. FindFirstChild behavior

— The title doesn’t really matter to be honest, and I’m aware of what the differences between these functions are.

Does FindFirstChildOfClass and the other methods (ex. FindFirstAncestor) share the same behavior as FindFirstChild?:
FindFirstChild is approx. ~20% slower than using the dot operator, but it doesn’t state that for the other functions other than on the FindFirstChild page.

FindFirstChild of class returns the first child of a class. Whereas FindFirstChild returns the first child of the name. If none exist, both return nil instead of giving a error.
I’m assuming your question would probably be the same as FindFirstChild. It finds something of a certain value, so it might be identical or similar, or completely different.

You are misunderstanding the question, which I expected.
Anyways, all I’m curious about is if those functions share the ~20% delay as well.

I think I did try to answer.
Just incase you didn’t see:

Yes, however would does not answer my question

1 Like

Then I can’t really help much. If Roblox hasn’t documented it you probably need to test yourself or hope someone that knows sees this post.

1 Like

Testing such things is tricky due to delays, etc.
But yes it seems like I need to do that.

1 Like

All of the FindFirstChild methods will be slower than the dot operator due to the way they access their information.

Think of every instance as having a hidden table representing its “children.” Whenever you use the dot operator to attempt to index a value that is not already a property/method of the instance, the hidden table will then be indexed. This process is quick, but ROBLOX throws an error if the index does not exist, which is problematic.

The FindFirstChild family of methods do not directly index the hidden table of children; instead, they iterate through the table and compare every object found against whatever criteria they are looking for–“Name” for FindFirstChild, “ClassName” for FindFirstChildOfClass, etc. This takes longer because the process of iterating through this table has to happen, even if the instance only has one or even zero children (unless ROBLOX has optimized these functions to handle these cases, that I cannot say).

FindFirstChildWhichIsA will take longer than the previously-mentioned methods because it performs a more intensive comparison operation since it respects inheritance.

However, the FindFirstAncestor family of methods are a little different. Because the “Parent” property of an instance is public, this family of methods is mostly just a convenient way of repeatedly evaluating whether or not an instance’s parent has properties that match the specified criteria up until top-most instance is reached, at which point the search has found nothing and returns nil, but these operators also tend to be faster than performing the same operation in a user-level Lua implementation, at least from what I can determine experimentally.


Bit late, but I did a benchmark using Boatbomber’s benchmarking module:

Thanks a lot, man; this benchmark really helped me. :+1:

2 years after :sob::sob: nice benchmark though, pretty interesting to look at