If you want to know all triangles that are hit by the ray, you have to check all of them. However, that doesn't mean that you have to check each of them individually. Usually, you apply some sort of space partitioning to your scene and group related objects in a bounding volume hierarchy. Then it gets a lot more efficient because you can drop multiple triangles with a single check.
For example, consider a scene with a rectangular area. You might subdivide this area into a 10x10 grid. Now check which parts of the grid are hit by the ray. All objects located in grid cells that aren't hit by the ray can be discarded and you only need to check the remaining objects. Now let's say that one of the hit objects is a human. Before you test the individual triangles, you narrow down the affected area in multiple substeps by checking against its bounding volume hierarchy. The traversal of the hierarchy might look like this: upper body hit -> left arm hit -> hand hit -> thumb hit. So with 4 checks, you can discard all triangles of the humans' mesh that do not belong to the thumb.
In case you only want to find the first triangle that is hit by the ray, you can also sort all hit cells and objects by distance before performing detailed tests. Then you start your checks at the closest object and continue until you get the first hit.