Skip to content

Add caching for function and method ffi_cifs #795

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

Merged
merged 3 commits into from
Oct 5, 2017

Conversation

tdermendjiev
Copy link
Contributor

@tdermendjiev tdermendjiev commented Sep 13, 2017

As unifying ffi signatures in metadata-generator would lead to insufficient ffi metadata in ios-runtime only ffi_cif caching in FFICall initialization is implemented.

@ns-bot
Copy link

ns-bot commented Sep 13, 2017

Can one of the admins verify this patch?

1 similar comment
@ns-bot
Copy link

ns-bot commented Sep 13, 2017

Can one of the admins verify this patch?


for(size_t i = 0; i < signature.size(); i++) {
seed <<= 4;
seed |= signature[i]->type;
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd recommend using the Fowler–Noll–Vo hash function. This one seems to not be distributive enough.

@tdermendjiev tdermendjiev force-pushed the tdermendzhiev/ffi-cif-caching branch from 0d7e2a3 to 7f8ee77 Compare October 2, 2017 14:48
std::unordered_map<std::vector<const ffi_type*>, std::shared_ptr<ffi_cif>, SignatureHash>::const_iterator it = FFICache::global()->cifCache.find(this->signatureVector);

if (it == FFICache::global()->cifCache.end()) {
std::shared_ptr<ffi_cif> shared(new ffi_cif, deleteCif);
Copy link
Contributor

@ivanbuhov ivanbuhov Oct 4, 2017

Choose a reason for hiding this comment

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

I find it a bit confusing that a method called checkForExistingCif actually creates a new cif in case there is no existing one. I suggest renaming the method (e.g. getCif or something) or moving the cif creation logic outside the method.
However, this is more or less a subjective statement, so if you don't agree, I am perfectly fine leaving it as is.

class FFICache {

public:
std::unordered_map<std::vector<const ffi_type*>, std::shared_ptr<ffi_cif>, SignatureHash> cifCache;
Copy link
Contributor

Choose a reason for hiding this comment

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

I suggest you declare a new typedef in order to avoid repeating the whole std::unordered_map<std::vector<const ffi_type*>, std::shared_ptr<ffi_cif>, SignatureHash> everywhere you need it.

Copy link
Contributor

@mbektchiev mbektchiev left a comment

Choose a reason for hiding this comment

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

👍 Nice work!

@tdermendjiev tdermendjiev merged commit 3f6bc42 into master Oct 5, 2017
@tdermendjiev tdermendjiev deleted the tdermendzhiev/ffi-cif-caching branch October 5, 2017 07:28
@mbektchiev mbektchiev added this to the 3.3.0 milestone Oct 24, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants