Skip to content

Configuration performance improvements and functionality enhancemens.#1452

Merged
jturner65 merged 5 commits intofacebookresearch:masterfrom
jturner65:Config_PerfAndFuncs
Aug 26, 2021
Merged

Configuration performance improvements and functionality enhancemens.#1452
jturner65 merged 5 commits intofacebookresearch:masterfrom
jturner65:Config_PerfAndFuncs

Conversation

@jturner65
Copy link
Copy Markdown
Contributor

Motivation and Context

This PR has some performance and functionality improvements/expansions for the Configurations, expanding upon the work of this PR..

How Has This Been Tested

Locally c++ and python

Types of changes

  • Docs change / refactoring / dependency upgrade
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have completed my CLA (see CONTRIBUTING)
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@facebook-github-bot facebook-github-bot added the CLA Signed Do not delete this pull request or issue due to inactivity. label Aug 26, 2021
@jturner65 jturner65 changed the title Config perf and funcs Configuration performance improvements and functionality enhancemens. Aug 26, 2021
const ConfigStoredType desiredType = configStoredTypeFor<T>();
if (mapIter != valueMap_.end() &&
(mapIter->second.getType() == desiredType)) {
return valueMap_.at(key).get<T>();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
return valueMap_.at(key).get<T>();
return mapIter->second.get<T>();

;)

Comment on lines 370 to 371
T val = valueMap_.at(key).get<T>();
valueMap_.erase(key);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
T val = valueMap_.at(key).get<T>();
valueMap_.erase(key);
valueMap_.erase(mapIter);

;)

@jturner65 jturner65 force-pushed the Config_PerfAndFuncs branch from f7c232a to ba14fc3 Compare August 26, 2021 16:30
Copy link
Copy Markdown
Contributor

@aclegg3 aclegg3 left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Copy Markdown
Contributor

@mosra mosra left a comment

Choose a reason for hiding this comment

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

Looks good! One minor thing left.

@@ -345,74 +365,65 @@ class Configuration {
// ****************** Value removal ******************
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Did you add the float overload for set() or not? I think it could be a nice "annoyance removal" feature to avoid having to cast every other thing.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I can do that

bool hasSubconfig(const std::string& key) const {
return (configMap_.count(key) > 0);
ConfigMapType::const_iterator mapIter = configMap_.find(key);
return (mapIter != configMap_.end());
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Here it could have stayed as the count(), i don't think STL is that stupid to look it up more than once :) But this consistent at least.

Copy link
Copy Markdown
Contributor Author

@jturner65 jturner65 Aug 26, 2021

Choose a reason for hiding this comment

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

I looked at the underlying code and find looked a bit quicker :D

template<typename _Key, typename _Value,
	   typename _Alloc, typename _ExtractKey, typename _Equal,
	   typename _H1, typename _H2, typename _Hash, typename _RehashPolicy,
	   typename _Traits>
    auto
    _Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal,
	       _H1, _H2, _Hash, _RehashPolicy, _Traits>::
    find(const key_type& __k) const
    -> const_iterator
    {
      __hash_code __code = this->_M_hash_code(__k);
      std::size_t __n = _M_bucket_index(__k, __code);
      __node_type* __p = _M_find_node(__n, __k, __code);
      return __p ? const_iterator(__p) : end();
    }
  template<typename _Key, typename _Value,
	   typename _Alloc, typename _ExtractKey, typename _Equal,
	   typename _H1, typename _H2, typename _Hash, typename _RehashPolicy,
	   typename _Traits>
    auto
    _Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal,
	       _H1, _H2, _Hash, _RehashPolicy, _Traits>::
    count(const key_type& __k) const
    -> size_type
    {
      __hash_code __code = this->_M_hash_code(__k);
      std::size_t __n = _M_bucket_index(__k, __code);
      __node_type* __p = _M_bucket_begin(__n);
      if (!__p)
	return 0;

      std::size_t __result = 0;
      for (;; __p = __p->_M_next())
	{
	  if (this->_M_equals(__k, __code, __p))
	    ++__result;
	  else if (__result)
	    // All equivalent values are next to each other, if we
	    // found a non-equivalent value after an equivalent one it
	    // means that we won't find any new equivalent value.
	    break;
	  if (!__p->_M_nxt || _M_bucket_index(__p->_M_next()) != __n)
	    break;
	}
      return __result;
    }

Copy link
Copy Markdown
Contributor Author

@jturner65 jturner65 Aug 26, 2021

Choose a reason for hiding this comment

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

(doesn't go through the entire bucket)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Wow, good to know.

@jturner65 jturner65 merged commit 6ddf898 into facebookresearch:master Aug 26, 2021
@jturner65 jturner65 deleted the Config_PerfAndFuncs branch August 26, 2021 18:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed Do not delete this pull request or issue due to inactivity.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants