Skip to content

Unnecessary Boxing and Increased Memory Usage #665

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

Open
zqll4 opened this issue Jan 9, 2025 · 0 comments
Open

Unnecessary Boxing and Increased Memory Usage #665

zqll4 opened this issue Jan 9, 2025 · 0 comments

Comments

@zqll4
Copy link

zqll4 commented Jan 9, 2025

After analyzing the memory usage, it was observed that the code causes boxing, resulting in unnecessary objects being created, which leads to increased memory consumption.

class IntFieldMutator implements UniFieldMutator {
    public int read(Component c, Field f) {
        try {
            return (Integer)f.get(c);
        } catch (ReflectionException var4) {
            ReflectionException e = var4;
            throw new RuntimeException(e);
        }
    }
}

The casting to Integer causes an unnecessary object creation when the method returns an int. This can be avoided by directly handling primitive types, which would help reduce memory overhead.

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

No branches or pull requests

1 participant