Skip to content

Conversation

tenplus1
Copy link
Member

optimizations by localising math functions.

localise math functions
localise math functions
localise math functions
localise math function
@SmallJoker
Copy link
Member

Do these changes make a measurable performance difference on your side? How big of a difference is it?

@tenplus1
Copy link
Member Author

@SmallJoker - A few ms here and there, although Nether generation does feel a lot smoother.

@Treer
Copy link
Collaborator

Treer commented Dec 21, 2024

I made the original local math function code that tenplus1 is adding to.

It was long enough ago that I don't recall how much speed testing I did or which lua implementation it was on. Any testing I'd done would have been in an earlier (not-nether) mod that used the same kind of mapgen. iirc I was only bothering to make local math functions if an operation was called many times in an inner loop.

The big reason to avoid potentially-premature optimization is the added code complexity/legibility/maintenance, and I don't think this applies to tenplus1's changes because they are extremely readable, and also consistent with how the code is already written, enough that they probably make the code more consistent and predictable.

So I can't say I have a problem with these changes, regardless of whether there's a noticeable performance difference. (as nice as it would be to know whether nether go faster)

@tenplus1
Copy link
Member Author

le Push :P

Copy link
Member

@SmallJoker SmallJoker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test setup:

  • Luanti 5.14.0-dev
  • LuaJIT 2.1.0-beta3 (Ubuntu repository, libluajit-5.1-2)
  • World with dummy back-end
  • Teleported into a known nether location with master and PR, and explored most of the (gigantic) cavern.

Testing code:

-- (bottom lines of mapgen.lua)
minetest.register_on_generated(function(...)
	local start = core.get_us_time()
	on_generated(...)
	-- print millisecond time
	print(("%.2f"):format((core.get_us_time() - start) / 1000))
end)
  master PR 83
Samples 95 133
Average / ms 65.56 68.99
Median / ms 61.4 64.87
     
Time diff. / %   5.65

Interestingly, this PR does result in decreased performance. Would you please be so nice to test this on your system?

@tenplus1
Copy link
Member Author

Very strange indeed, I teleported to the nether, stood in the exact same spot and did "/deleteblocks here 20" to regenerate an area 10 times, without the changes the final block times were (67.33, 66.90, 55.16) and with the changes the final block times were (48.95, 53.17, 61.34). This is on an AMD Ryzen 7 7840HS with 780M graphics.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants