Skip to content

Significant Performance Issue in TreeCutter.findTree for Large / Connected Trees #9284

@KhloeLeclair

Description

@KhloeLeclair

Description

Within the findTree method, specifically on lines 153 and 171, the following line of code is present:

if (!logs.contains(currentPos) && !visited.add(currentPos))

I hope drawing attention to it is enough to prove my point, but as logs is an ArrayList and visited is a HashSet you're effectively guarding an O(1) check behind an O(n) check rather than doing the opposite. For a moderately sized tree farm, this can cause incredibly long execution times in this method and lead a server to hang. On the server I play on, this specific issue has caused the server to hang long enough for a health watchdog to forcibly restart it no less than three times in the past week.

I can reproduce this behavior by creating a fresh instance of Minecraft 1.21.1 with Neoforge 21.1.209, installing only Create 6.0.6, and building a sufficiently large plot of mangrove trees before attempting to harvest them with a contraption using saws.

Game Log

https://mclo.gs/3YOIezn

Debug Information

Client Info
Create:
	Mod Version: 6.0.6
	Mod Git Commit: 20ad05b5e525166018d21e88c96986f867c7088f
	Ponder Version: 1.0.56
	NeoForge Version: 21.1.209
	Minecraft Version: 1.21.1

Graphics:
	Flywheel Version: 1.0.4
	Flywheel Backend: flywheel:indirect
	OpenGL Renderer: NVIDIA GeForce RTX 3090/PCIe/SSE2
	OpenGL Version: 4.6.0 NVIDIA 566.36
	Graphics Mode: fancy
	PojavLauncher Detected: false

System Information:
	Operating System: Windows 10 (amd64) version 10.0
	Java Version: 21.0.7, Microsoft
	JVM Flags: 3 total; -XX:HeapDumpPath=MojangTricksIntelDriversForPerformance_javaw.exe_minecraft.exe.heapdump -Xms512m -Xmx4096m
	Memory: 151527264 bytes (144 MiB) / 1514143744 bytes (1444 MiB) up to 4294967296 bytes (4096 MiB)
	Total Memory: 1366418504 bytes (1303 MiB) / 1514143744 bytes (1444 MiB)
	CPU: AMD Ryzen 7 9700X 8-Core Processor @ 3.79 GHz; 8 cores / 16 threads on 1 socket(s)
	Graphics cards: none

Other Mods:
Server Info
Create:
	Mod Version: 6.0.6
	Mod Git Commit: 20ad05b5e525166018d21e88c96986f867c7088f
	Ponder Version: 1.0.56
	NeoForge Version: 21.1.209
	Minecraft Version: 1.21.1

System Information:
	Operating System: Windows 10 (amd64) version 10.0
	Java Version: 21.0.7, Microsoft
	JVM Flags: 3 total; -XX:HeapDumpPath=MojangTricksIntelDriversForPerformance_javaw.exe_minecraft.exe.heapdump -Xms512m -Xmx4096m
	Memory: 151527264 bytes (144 MiB) / 1514143744 bytes (1444 MiB) up to 4294967296 bytes (4096 MiB)
	Total Memory: 1366418504 bytes (1303 MiB) / 1514143744 bytes (1444 MiB)
	CPU: AMD Ryzen 7 9700X 8-Core Processor @ 3.79 GHz; 8 cores / 16 threads on 1 socket(s)
	Graphics cards: none

Other Mods:

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: confirmedIssue's details are known, it is consistently reproducible, and it needs a fixstatus: fixed in next releaseIssue will be fixed in the next releasetype: bugIssue where something isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions