While ray length does noticeably impact the performance, the presence of terrain seems to be a non-significant issue.
I ran a timed benchmark test with the following code to see if terrain and ray lengths would affect the overall performance:
wait(8)
local sum = 0
for o=1,50 do
local t= tick()
for i=1,60*70 do
workspace:FindPartOnRay(Ray.new(Vector3.new(math.random()*1000,2000,math.random()*1000),Vector3.new(0,-2000,0)),nil,true)
end
sum = sum + tick()-t
--print(tick()-t)
end
print(sum/50)
wait()
local sum = 0
for o=1,50 do
local t= tick()
for i=1,60*70 do
workspace:FindPartOnRay(Ray.new(Vector3.new(math.random()*1000,300,math.random()*1000),Vector3.new(0,-300,0)),nil,true)
end
sum = sum + tick()-t
--print(tick()-t)
end
print(sum/50)
It’s randomized to prevent possible result caching, and it averages the result of 50 iterations of 4200 iterations of 1000 stud and 300 stud ray casts, so the data below reflects the results of 4200 iterations on average.
When run on a world with only a single baseplate, the following results are (for 1000 stud and 300 stud respectively):
0.18865569591522
0.037233214378357
When run on a world with a 1024x1024x1024 generated terrain, the following results are:
0.18400784492493
0.043346810340881
Since doing 4200 ray casts on terrain appears to run virtually the same as on an empty baseplate, you’re good to go on terrain, its only the length that matters.