Skip to content

Conversation

denravonska
Copy link
Member

@denravonska denravonska commented Aug 9, 2018

Improve the speed of neural security access by converting the maps to unordered_map and trying to avoid multiple map lookups. This greatly increases the synchronization and block import speed.

It syncs from 0 using the network without any issues.

@denravonska denravonska added this to the Camilla milestone Aug 9, 2018
src/main.cpp Outdated
double votes = (1/distance)*multiplier;
temp_hashcount += votes;
mvCurrentNeuralNetworkHash[NeuralHash] = temp_hashcount;
double& hashcount = mvCurrentNeuralNetworkHash[NeuralHash];
Copy link
Member Author

Choose a reason for hiding this comment

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

No need to extract the hashCount here. It's good enough to do mvCurrentNeuralNetworkHash[NeuralHash] += votes.

Copy link
Member

@tomasbrod tomasbrod left a comment

Choose a reason for hiding this comment

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

I checked the code and, besides the comments, it should be fine.

// 6-13-2015 ONLY Count Each Neural Hash Once per GRC address / CPID (1 VOTE PER RESEARCHER)
std::string Security = ReadCache("currentneuralsecurity",GRCAddress).value;
const std::string& Security = ReadCache("currentneuralsecurity",GRCAddress).value;

This comment was marked as off-topic.

if(pindexBest && pindexBest->nVersion>=9)
{
ClearCache("neuralsecurity");
}
Copy link
Member

Choose a reason for hiding this comment

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

This is change of behaviour. But in this case it makes sense.
Please keep the comment and add a little note to it.

Copy link
Member Author

Choose a reason for hiding this comment

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

Will do!

src/main.cpp Outdated
}


void IncrementVersionCount(const std::string& Version)
Copy link
Member

Choose a reason for hiding this comment

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

What about axing this code? Same stats are now available on demand in getblockstats.

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh, it's not actually used for anything? Will axe.

std::string report = "Version, Popularity\n";
std::string row = "";
double pct = 0;
UniValue entry(UniValue::VOBJ);
entry.pushKV("Version","Popularity,Percent %");

Copy link
Member

Choose a reason for hiding this comment

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

whitespace error
Just axe this code.

Copy link
Member Author

@denravonska denravonska Aug 9, 2018

Choose a reason for hiding this comment

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

Happy to :) I'll double check the dependencies.

@denravonska denravonska force-pushed the optimize-neuralsecurity branch from 3825e6d to 6ccd1d2 Compare August 12, 2018 18:19
@denravonska
Copy link
Member Author

If we want to axe the RPC calls we should maybe do it in #1232

extern std::map<std::string, double> mvNeuralNetworkHash;
extern std::map<std::string, double> mvCurrentNeuralNetworkHash;
extern std::map<std::string, double> mvNeuralVersion;
extern std::unordered_map<std::string, double> mvNeuralNetworkHash;
Copy link
Member

Choose a reason for hiding this comment

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

imo we should typedef std::unordered_map<std::string, double> NeuralMap

would make this a little neater and then we can do the NeuralMap::iterator

Think this would look cleaner.

We should consider the same in another PR for std::map<std::string, StructCPID> if we can as well.

liking the use of unordered_map for optimizations

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll do a sweep of all the maps in a later PR.

@denravonska denravonska merged commit 0c1cc7c into gridcoin-community:development Oct 18, 2018
denravonska added a commit that referenced this pull request Apr 3, 2019
Added:
 - Add `rainbymagnitude` RPC command #1235 (@Foggyx420).
 - Add stake splitting and side staking #1265 (@jamescowens).
 - Detect and block Windows shutdown so wallet can exit cleanly #1309
   (@jamescowens).
 - Add message support to sendfrom and sendtoaddress #1400 (@denravonska).

Changed:
 - Configuration options are now case insensitive #294 (@Foggyx420).
 - Update command in beaconstatus help message #1312 (@chrstphrchvz).
 - Improve synchronization speeds:
   - Refactor superblock pack/unpack #1194 (@denravonska).
   - Optimize neuralsecurity calculations #1255 (@denravonska).
   - Reduce hash calculations when checking blocks #1206 (@denravonska).
 - Make display of private key in beaconstatus OPT-IN only #1275 (@Foggyx420).
 - Store Beacon keys in Wallet #1088 (@tomasbrod).
 - Use default colors for pie chart #1333 (@chrstphrchvz).
 - Show hand cursor when hovering clickable labels #1332 (@chrstphrchvz).
 - Update README.md #1337 (@Peppernrino).
 - Fix integer overflow with displayed nonce #1297 (@personthingman2).
 - Improve application cache performance #1317 (@denravonska).
 - Improve reorg speeds #1263 (@denravonska).
 - Update Polish translation #1375 (@michalkania).

Fixed:
 - Remove expired polls from overview page #1250 (@personthingman2).
 - Fix plural text on block age #1304 (@scribblemaniac).
 - Fix researcher staking issue if your chain head was staked by you,
   #1299 (@denravonska).
 - Fix incorrect address to grcpool node #1314 (@wilkart).
 - Do not replace underscores by spaces in Qt Poll URLs #1327 (@tomasbrod).
 - Fix scraper SSL issues #1330 (@Foggyx420).

Removed:
 - Remove or merged several RPC commands #1228 (@Foggyx420):
    - `newburnaddress`, removed.
    - `burn2`: Removed.
    - `cpid`: Merged into `projects`.
    - `mymagnitude`: Merged into `magnitude`.
    - `rsa`: Removed, use `magnitude`.
    - `rsaweight`: Removed, use `magnitude`.
    - `proveownership`: Removed.
    - `encrypt`: Removed.
 - Remove obsolete POW fields from RPC responses #1358 (@jamescowens).
 - Remove obsolete netsoft fields for slight RAM requirement reduction
   #1336 (@denravonska).
 - Remove unused attachment functionality #1345 (@denravonska).
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.

3 participants