Skip to content

Performance issue or user error? #45

@pudy248

Description

@pudy248

I had expected Java-Python interop to be slow but it seems a little ridiculously and excessively slow. With Pyjinn interop, which I had assumed would be the faster and slightly better method:

eye_script = java.eval_pyjinn_script("def is_crouching():\n    return JavaClass(\"net.minecraft.client.Minecraft\").getInstance().player.isCrouching()")
is_crouching = eye_script.getFunction("is_crouching")
t = time.time()
for _ in range(10):
    is_crouching()
print(f"Time: {time.time() - t}")

This short example takes an entire 0.9 seconds to run 10 times. Let's try the java module instead:

def is_crouching():
    return java.JavaClass("net.minecraft.client.Minecraft").getInstance().player.isCrouching()
t1 = time.time()
for i in range(10):
    is_crouching()
print(f"Time: {time.time() - t1}")

Ok, it's 1.37 seconds now. Caching the player JavaObject cuts it down to 0.37 seconds, but that's still not really very good. I would assume these facilities are all built with reflection, but reflection is definitely not normally this slow. The same script entirely in Pyjinn runs essentially instantaneously, of course.

This can't possibly be just an IPC issue, even though that probably doesn't help, because the minescript Python module itself is quite able to interact with Java without any difficulty. Is there some better way to do this? How hard can it be to read a boolean?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions