mirror of
https://github.com/dashpay/dash.git
synced 2024-12-28 13:32:47 +01:00
595826ad63
5aad635
Use memset() to optimize prevector::resize() (Evan Klitzke)e46be25
Reduce redundant code of prevector and speed it up (Akio Nakamura)f0e7aa7
Add new prevector benchmarks. (Evan Klitzke) Pull request description: This branch optimizes various `prevector` operations, especially resizing vectors. While profiling the `loadblk` thread I noticed that a lot of time was being spent in `prevector::resize()` which led to this work. I have some data here indicating that it takes up **37%** of the time in `ReadBlockFromDisk()`: https://monad.io/readblockfromdisk.svg This branch improves things significantly. For trivial types, the new results for the prevector benchmark are: * `PrevectorClearTrivial` which tests `prevector::clear()` becomes 24.6x faster * `PrevectorDestructorTrivial` which tests `prevector::~prevector()` becomes 20.5x faster * `PrevectorResizeTrivial` which tests `prevector::resize()` becomes 20.3x faster Note that in practice it looks like the prevector is only used to contain `unsigned char` types, which is a trivial type. The benchmarks are testing a bit of an extreme case, but the changes here are motivated by the profiling data for `ReadBlockFromDisk()` I linked to above. The pull request here consists of a series of three commits: * The first adds new benchmarks but does not change the prevector code. * The second is from @AkioNak , and merges some prevector optimizations he submitted in #11988 * The third optimizes `prevector::resize()` to use `memset()` when the prevector contains trivially constructible types Tree-SHA512: 28f7cbb91a19f9f43b6a5942781d7eb2e3197389186b666f086b69df12bee37773140f765426d715bfb8ebff79cb27a5f1206d0325b54b4aa65598b50fb18368
98 lines
2.3 KiB
C++
98 lines
2.3 KiB
C++
// Copyright (c) 2009-2010 Satoshi Nakamoto
|
|
// Copyright (c) 2009-2015 The Bitcoin Core developers
|
|
// Distributed under the MIT software license, see the accompanying
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
#ifndef BITCOIN_COMPAT_H
|
|
#define BITCOIN_COMPAT_H
|
|
|
|
#if defined(HAVE_CONFIG_H)
|
|
#include "config/dash-config.h"
|
|
#endif
|
|
|
|
#include <type_traits>
|
|
|
|
// GCC 4.8 is missing some C++11 type_traits,
|
|
// https://www.gnu.org/software/gcc/gcc-5/changes.html
|
|
#if defined(__GNUC__) && __GNUC__ < 5
|
|
#define IS_TRIVIALLY_CONSTRUCTIBLE std::is_trivial
|
|
#else
|
|
#define IS_TRIVIALLY_CONSTRUCTIBLE std::is_trivially_constructible
|
|
#endif
|
|
|
|
#ifdef WIN32
|
|
#ifdef _WIN32_WINNT
|
|
#undef _WIN32_WINNT
|
|
#endif
|
|
#define _WIN32_WINNT 0x0501
|
|
#ifndef WIN32_LEAN_AND_MEAN
|
|
#define WIN32_LEAN_AND_MEAN 1
|
|
#endif
|
|
#ifndef NOMINMAX
|
|
#define NOMINMAX
|
|
#endif
|
|
#ifdef FD_SETSIZE
|
|
#undef FD_SETSIZE // prevent redefinition compiler warning
|
|
#endif
|
|
#define FD_SETSIZE 1024 // max number of fds in fd_set
|
|
|
|
#include <winsock2.h> // Must be included before mswsock.h and windows.h
|
|
|
|
#include <mswsock.h>
|
|
#include <windows.h>
|
|
#include <ws2tcpip.h>
|
|
#else
|
|
#include <sys/fcntl.h>
|
|
#include <sys/mman.h>
|
|
#include <sys/select.h>
|
|
#include <sys/socket.h>
|
|
#include <sys/types.h>
|
|
#include <net/if.h>
|
|
#include <netinet/in.h>
|
|
#include <netinet/tcp.h>
|
|
#include <arpa/inet.h>
|
|
#include <ifaddrs.h>
|
|
#include <limits.h>
|
|
#include <netdb.h>
|
|
#include <unistd.h>
|
|
#endif
|
|
|
|
#ifndef WIN32
|
|
typedef unsigned int SOCKET;
|
|
#include "errno.h"
|
|
#define WSAGetLastError() errno
|
|
#define WSAEINVAL EINVAL
|
|
#define WSAEALREADY EALREADY
|
|
#define WSAEWOULDBLOCK EWOULDBLOCK
|
|
#define WSAEMSGSIZE EMSGSIZE
|
|
#define WSAEINTR EINTR
|
|
#define WSAEINPROGRESS EINPROGRESS
|
|
#define WSAEADDRINUSE EADDRINUSE
|
|
#define WSAENOTSOCK EBADF
|
|
#define INVALID_SOCKET (SOCKET)(~0)
|
|
#define SOCKET_ERROR -1
|
|
#endif
|
|
|
|
#ifdef WIN32
|
|
#ifndef S_IRUSR
|
|
#define S_IRUSR 0400
|
|
#define S_IWUSR 0200
|
|
#endif
|
|
#else
|
|
#define MAX_PATH 1024
|
|
#endif
|
|
|
|
#if HAVE_DECL_STRNLEN == 0
|
|
size_t strnlen( const char *start, size_t max_len);
|
|
#endif // HAVE_DECL_STRNLEN
|
|
|
|
bool static inline IsSelectableSocket(const SOCKET& s) {
|
|
#ifdef WIN32
|
|
return true;
|
|
#else
|
|
return (s < FD_SETSIZE);
|
|
#endif
|
|
}
|
|
|
|
#endif // BITCOIN_COMPAT_H
|