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

Object.hashCode is used by RubyHash, but not specialized for any types #4042

Closed
headius opened this issue Jul 29, 2016 · 1 comment
Closed

Comments

@headius
Copy link
Member

headius commented Jul 29, 2016

Our implementation of hashing for RubyHash insertion just calls hashCode on the target object. This has only one implementation in our hierarchy that dynamically tries to call hash.

    public int hashCode() {
        ThreadContext context = getRuntime().getCurrentContext();
        IRubyObject hashValue = invokeChecked(context, this, sites(context).hash_checked);
        if (hashValue == null) return super.hashCode();
        if (hashValue instanceof RubyFixnum) return (int) RubyNumeric.fix2long(hashValue);
        return nonFixnumHashCode(hashValue);
    }

For some core types, this extra logic could be omitted as long as hash was still the built-in version. As it stands now, even with call site caching this code will be heavily contended and a potential bottleneck for hash access.

@headius
Copy link
Member Author

headius commented Jul 29, 2016

Ugh...nevermind. IDE fail. It was still calculating subclass overrides, and we do appear to override it appropriately in many classes.

@headius headius closed this as completed Jul 29, 2016
@headius headius added this to the Invalid or Duplicate milestone Jul 29, 2016
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