Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Explicitly pass null filter when creating SecureJar/UnionFS #19

Merged
merged 1 commit into from
Aug 25, 2023

Conversation

embeddedt
Copy link
Member

UnionFileSystem.testFilter contains an optimization intended for the case where no path filter is set:

https://github.com/McModLauncher/securejarhandler/blob/1dedb0655d9f4b8cf310ea7095b38c7a978a42ab/src/main/java/cpw/mods/niofs/union/UnionFileSystem.java#L397

However, all of the code paths creating commonly-used UnionFS instances in FML are passing non-null (a, b) -> true lambdas, defeating this optimization. I have frequently seen testFilter appearing as a hotspot in my profiling while working on ModernFix.

The solution is quite simple: start passing null instead of a lambda. I've gone through the codebase and replaced all the lambdas matching this pattern.

Would appreciate review from someone familiar with this part of the codebase.

Using a non-null lambda defeats the optimization in UnionFS that skips the code in testFilter
@@ -38,7 +38,7 @@ protected IModLocator.ModFileOrException createMod(Path... path) {
var sj = SecureJar.from(
Manifest::new,
jar -> jar.moduleDataProvider().findFile(MODS_TOML).isPresent() ? mjm : JarMetadata.from(jar, path),
(root, p) -> true,
null,
Copy link
Member Author

Choose a reason for hiding this comment

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

I've tested this specific class' change in production using my Java agent and an equivalent ASM transformer. The other changes have not been tested yet.

@sciwhiz12 sciwhiz12 added the enhancement New feature or request label Aug 23, 2023
@marchermans marchermans merged commit 7810b97 into neoforged:main Aug 25, 2023
1 check passed
Jab125 added a commit to Jab125/FancyModLoader that referenced this pull request Sep 24, 2023
Pass null for an "always" filter instead of a separate lambda (neoforged#19)
@embeddedt embeddedt deleted the use-null-filters branch January 10, 2024 18:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants