Load main dic in native
Follow up to Id57dce51
bug: 3219819
Change-Id: I00e11ef21d0252ffa88c12dffb9c55b0f2e19a66
diff --git a/native/src/defines.h b/native/src/defines.h
index 59eaa41..71aaf28 100644
--- a/native/src/defines.h
+++ b/native/src/defines.h
@@ -36,45 +36,47 @@
static double profile_old[PROF_BUF_SIZE];
static unsigned int profile_counter[PROF_BUF_SIZE];
-#define PROF_RESET prof_reset();
-#define PROF_COUNT(prof_buf_id) ++profile_counter[prof_buf_id];
-#define PROF_OPEN PROF_RESET;PROF_START(PROF_BUF_SIZE - 1);
-#define PROF_START(prof_buf_id) PROF_COUNT(prof_buf_id);profile_old[prof_buf_id] = (clock());
-#define PROF_CLOSE PROF_END(PROF_BUF_SIZE - 1);PROF_OUTALL;
-#define PROF_END(prof_buf_id) profile_buf[prof_buf_id] += ((clock()) - profile_old[prof_buf_id]);
-#define PROF_CLOCKOUT(prof_buf_id) LOGI("%s : clock is %f", __FUNCTION__,\
- (clock() - profile_old[prof_buf_id]));
-#define PROF_OUTALL LOGI("--- %s ---", __FUNCTION__); prof_out();
+#define PROF_RESET prof_reset()
+#define PROF_COUNT(prof_buf_id) ++profile_counter[prof_buf_id]
+#define PROF_OPEN do { PROF_RESET; PROF_START(PROF_BUF_SIZE - 1); } while(0)
+#define PROF_START(prof_buf_id) do { \
+ PROF_COUNT(prof_buf_id); profile_old[prof_buf_id] = (clock()); } while(0)
+#define PROF_CLOSE do { PROF_END(PROF_BUF_SIZE - 1); PROF_OUTALL; } while(0)
+#define PROF_END(prof_buf_id) profile_buf[prof_buf_id] += ((clock()) - profile_old[prof_buf_id])
+#define PROF_CLOCKOUT(prof_buf_id) \
+ LOGI("%s : clock is %f", __FUNCTION__, (clock() - profile_old[prof_buf_id]))
+#define PROF_OUTALL do { LOGI("--- %s ---", __FUNCTION__); prof_out(); } while(0)
-static void prof_reset(void){
- for(int i = 0;i < PROF_BUF_SIZE;++i){
+static void prof_reset(void) {
+ for (int i = 0; i < PROF_BUF_SIZE; ++i) {
profile_buf[i] = 0;
profile_old[i] = 0;
profile_counter[i] = 0;
}
}
-static void prof_out(void){
+static void prof_out(void) {
if (profile_counter[PROF_BUF_SIZE - 1] != 1) {
LOGI("Error: You must call PROF_OPEN before PROF_CLOSE.");
}
LOGI("Total time is %6.3f ms.",
- profile_buf[PROF_BUF_SIZE - 1] * 1000 / (double) CLOCKS_PER_SEC);
+ profile_buf[PROF_BUF_SIZE - 1] * 1000 / (double)CLOCKS_PER_SEC);
double all = 0;
- for(int i = 0; i < PROF_BUF_SIZE - 1; ++i){
+ for (int i = 0; i < PROF_BUF_SIZE - 1; ++i) {
all += profile_buf[i];
}
- if(all == 0) all = 1;
- for(int i = 0; i < PROF_BUF_SIZE - 1; ++i){
- if(profile_buf[i] != 0) {
+ if (all == 0) all = 1;
+ for (int i = 0; i < PROF_BUF_SIZE - 1; ++i) {
+ if (profile_buf[i] != 0) {
LOGI("(%d): Used %4.2f%%, %8.4f ms. Called %d times.",
- i, (profile_buf[i] * 100 /all),
- profile_buf[i] * 1000 / (double) CLOCKS_PER_SEC, profile_counter[i]);
- }
+ i, (profile_buf[i] * 100 / all),
+ profile_buf[i] * 1000 / (double)CLOCKS_PER_SEC, profile_counter[i]);
+ }
}
}
#else // FLAG_DBG
+#define LOGE
#define LOGI
#define DEBUG_DICT false
#define DEBUG_DICT_FULL false
@@ -99,6 +101,11 @@
#define U_SHORT_MAX 1 << 16
#endif
+// Define this to use mmap() for dictionary loading. Undefine to use malloc() instead of mmap().
+// We measured and compared performance of both, and found mmap() is fairly good in terms of
+// loading time, and acceptable even for several initial lookups which involve page faults.
+#define USE_MMAP_FOR_DICTIONARY
+
// 22-bit address = ~4MB dictionary size limit, which on average would be about 200k-300k words
#define ADDRESS_MASK 0x3FFFFF