-
Notifications
You must be signed in to change notification settings - Fork 0
Home
This lists changes I would like to make:
Replace std::bind with lambda:
https://stackoverflow.com/questions/15598607/when-should-i-use-stdbind
std::bind will probably be deprecated in the future
https://stackoverflow.com/questions/33835922/why-should-bind-be-deprecated
Scott Meyers - Effective Modern C++ Item 34.
https://youtu.be/zt7ThwVfap0?t=1511
- Template parameters need better names. T & F are not descriptive! std uses things like InputIterator (although maybe that's because they have a defined interface?)
- Template parameters need type trait constraints. Until we have concepts in C++20 it is a good idea to use type traits to assert what the template arguments are https://stackoverflow.com/questions/47698552/how-to-check-if-template-argument-is-a-callable-with-a-given-signature
For instance, boost callable traits: https://www.boost.org/doc/libs/1_68_0/libs/callable_traits/doc/html/index.html
https://github.com/nanocurrency/raiblocks/pull/1273/files
* Wiki "Build instructions" incorrect boost path
- Use flat_map, sorted vector or custom block allocator, instead of raw std::map. #define BOOST_POOL_NO_MT#include <boost/pool/pool_alloc.hpp>#include int main(){ typedef boost::fast_pool_allocator<int, boost::default_user_allocator_new_delete, boost::details::pool::default_mutex, 64, 128> allocator; std::list<int, allocator> l; for (int i = 0; i < 1000; ++i) l.push_back(i); l.clear(); boost::singleton_pool<boost::fast_pool_allocator_tag, sizeof(int)>:: purge_memory(); }
From https://theboostcpplibraries.com/boost.pool
- Profile hot path and improve efficiencies there
- Add code coverage reports. Code coverage with gcov & lcov? https://medium.com/@naveen.maltesh/generating-code-coverage-report-using-gnu-gcov-lcov-ee54a4de3f11
- Add clang-tidy to pipeline
- Use more std algorithms
- Range loops, also boost::range?
- Line length to clang format? Lines too long. Conditions can be factored out in if statements.
- Replace std::function with auto, template or another inplaced version. It can have a SBO like std::string for small callables, otherwise otherwise it allocates.
If using callables as a function argument, then declare it as a template parameter.
From the SG14 (gaming) working group have an implementation: https://github.com/WG21-SG14/SG14/blob/master/SG14/inplace_function.h
Or even make your own: https://www.youtube.com/watch?v=VY83afAJUIg
https://stackoverflow.com/questions/18365532/should-i-pass-an-stdfunction-by-const-reference
- Reorder member variables to reduce unnecessary packing and less cache misses by joining frequently used data together. Be careful about shared memory as it locks the whole cache line. https://stackoverflow.com/questions/892767/optimizing-member-variable-order-in-c
- Common.hpp another place that namespace std is being polluted
- Investigate if it is possible to run a multi-node (i.e run on both live and beta network at once).
-
(done)
.gitmodules references beast - Check that Big5 are noexcept where possible (especially move constructors)
- Remove operator[] being used with std::map/std::unordered_map. See Effective C++ STL Item. Use find() and an InsertOrUpdate() method.
- Avoid allocations. Consider using jemalloc. ::operator new(size_t) is most likely a wrapper around std::malloc in most implementations, which is good for large blocks (array/vector), but is inefficient for much smaller ones.
- Backup representative in case your one goes down?
- Are shared_ptrs abused?
- Replace polymorphic inheritance, with static inheritance with templates?
- Any branches which can be removed? branches which can be removed (make testing harder). if (type == UDP => ).
- Avoid syntax like this: for (auto i (node.wallets.items.begin ()), n (node.wallets.items.end ()); i != n; ++i)
It is the old iterator style for loop, use a ranged for loop (I've seen them elsewhere in the code, but it should be consistent)
for (auto wallet :: node.wallets.items) { }
* Why is a std::deque used in node.cpp line 3271? This data structure is generally only used when it is desirable to insert at the beginning (in addition to the end), otherwise a std::vector is more beneficial.
- 6 - Raw for loops don't show intent like a standard algorithm does, and I prefer to use an algorithm where possible. In the same area of code, replace the whole loop with something like: std::transform(roots.begin(), roots.end(), std::back_inserter(result), [](const auto& root) { return root->election->status.winner; }
Something like: for (auto & entry : list_probable_rep_weights ()) { result = result + entry.rep_weight.number (); }
Can be replaced with: auto result = std::accumulate(list_probable_rep_weights.begin(), list_probable_rep_weights.end(), static_castrai::uint128_t(0), [](auto count, auto& entry) { return count + entry.rep_weight.number (); }
Or even better with ranges v3 library it becomes: auto result = ranges::accumulate(list_probable_rep_weights, static_castrai::uint128_t(0), [](auto count, auto& entry) { return count + entry.rep_weight.number (); }
(I'm sure there's many other useful algorithms that can be used...).
- Can precompiled headers speed up build? It's mostly dependencies which take time I think. Need to measure.
- Too many public variables. Encapsulation, well defined interfaces..
- rpc.hpp mrai_ should be swapped to be consistent. same with payment & work
* Order of includes should be grouped by most dependent to least to make sure header files contain all necessary include dependencies to be parsed. - common.hpp - make deserialize virtual? seems strange it is not as seems part of the interface. to_bytes could return unique_ptr?
- lib/utility.hpp, should observer_set, notify() use std::forward for the variadic template?
* entry.cpp - a lot of hardcoded strings - Multi-lingual?
- openclwork.cpp use C++ API with exceptions rather than error codes
- opencl not enabled by default. My CPU fan sounds like it going to take off when precomputing POW!
https://github.com/nanocurrency/raiblocks/wiki/RPC-protocol#wallet-destroy, output has: "destroyed": "1"- Config.ini QT gui
* Subscribe to events? In Ethereum you can use Websocket or IPC provider, and subscribe to events (needs 2 way communication). Currently we do allow RPC callback which is defined inside config.json.* Eco POW in config.ini? Instead of doing it as fast as possible and make the CPU sound like it's taking off. Have an option to sleep in-between? https://1nano.co/receiving-nano/* README.md https://travis-ci.org/nanocurrency/raiblocks is incorrect - store_iterator Make our iterators "range for aware" https://stackoverflow.com/questions/8164567/how-to-make-my-custom-type-to-work-with-range-based-for-loops
- secure_zero_memory - Remove any form of keys from the stack/heap after use.
- Improve compile-time performance by moving templates to source file and explicitly instantiate ones we know we need. Like with nano::timer. all the common std::chrono variants, or just ones we are using.