Would re-writing parts of my code in c# noticibly boost performance?

Do you have some performance measurements?

It certainly gives cpu’s branch predictor a run for its money :rofl:

3 Likes

honestly I’m not exactly sure how to measure anything past FPS, which has improved over the course of optimization. around 10 fps drops when loading tiles with the original code (more than 1 tile), now its down to about a 4 fps drop.

fps when not loading tiles is and always has been stable (144 fps)

Use the profiler. Fps is statistical, it doesn’t really account properly for occasional one off stutters caused by doing too much in a single frame.

alright ill take a look, is there any specific number i should be looking at?

I use this to measure some specific code section:

	var t0 = Time.get_ticks_msec()	
	...do something...
	var t1 = Time.get_ticks_msec()
	prints("something took", t1-t0, "ms")
1 Like

Start the profiler and look for peaks in the chart. If there are no peaks - you’re good and don’t need to worry about optimizations. If there are peaks - select a peak and look at the times the specific functions ate up to determine which one is a bottleneck.

A worthwhile optimization (already suggested by @normalized) is to get all cell source ids (map.get_cell_source_id()) to an integer array in the beginning. The the smooth_tiles and connect_tile_to_adj functions get the cell source ids from that array instead of asking it from the map. I tested this briefly and the optimized version (call map.get_cell_source_id() only once per tile and access the int array nine times per tile) took only 40% of the time that unoptimized version (call map.get_cell_source_id()nine times per tile).

4 Likes

just added this and wow it helps a lot

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.