{"action":"created","issue":{"url":"https://api.github.com/repos/cnjinhao/nana/issues/280","repository_url":"https://api.github.com/repos/cnjinhao/nana","labels_url":"https://api.github.com/repos/cnjinhao/nana/issues/280/labels{/name}","comments_url":"https://api.github.com/repos/cnjinhao/nana/issues/280/comments","events_url":"https://api.github.com/repos/cnjinhao/nana/issues/280/events","html_url":"https://github.com/cnjinhao/nana/issues/280","id":276628464,"number":280,"title":"preformance issue with textbox","user":{"login":"wjiali6","id":23405286,"avatar_url":"https://avatars0.githubusercontent.com/u/23405286?v=4","gravatar_id":"","url":"https://api.github.com/users/wjiali6","html_url":"https://github.com/wjiali6","followers_url":"https://api.github.com/users/wjiali6/followers","following_url":"https://api.github.com/users/wjiali6/following{/other_user}","gists_url":"https://api.github.com/users/wjiali6/gists{/gist_id}","starred_url":"https://api.github.com/users/wjiali6/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wjiali6/subscriptions","organizations_url":"https://api.github.com/users/wjiali6/orgs","repos_url":"https://api.github.com/users/wjiali6/repos","events_url":"https://api.github.com/users/wjiali6/events{/privacy}","received_events_url":"https://api.github.com/users/wjiali6/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2017-11-24T14:13:20Z","updated_at":"2017-11-26T03:05:58Z","closed_at":null,"author_association":"NONE","body":"Profiling shows that there are mulptiple preformance issues with textbox implementation, some seem due to completely useless (seems) ,a lot of them calls one specific function\r\nvoid pre_calc_line(std::size_t pos, unsigned) override\r\nfrom text_editor.cpp line 671\r\n(.......\\cnjinhao\\nana\\source\\gui\\widgets\\skeletons\\text_editor.cpp)\r\nI don't see anything useful from this function ,can it be elininated ?\r\nBTW, I load a 14M gbk(after read into memory decoded to Windows UCS2 encoding) text file to a textbox object, the profiling shows that pre_calc_line takes about 65%~75% of whole loading process.\r\n\r\nThe following is code snips which do the work:\r\n\r\n#define  Timing(now,end,diff,expression ,buffer,workname)     \\\r\nnow= std::chrono::system_clock::now();\\\r\nexpression; \\\r\nend= std::chrono::system_clock::now();\\\r\ndiff = end-now;\\\r\nswprintf(buffer,L\"%s tooks \\t%lld ms\\n\",workname,std::chrono::duration_cast<std::chrono::milliseconds>(end-now).count()); \\\r\nOutputDebugString(buffer);\r\n__inline static void toUSC2(const std::string & str,std::wstring& wstr)\r\n{\r\n    TCHAR BUFFER[200];\r\n    ZeroMemory(BUFFER, sizeof(TCHAR) * 200);\r\n    auto size = ::MultiByteToWideChar(CP_ACP, 0, str.c_str(), str.size(), nullptr, 0);\r\n    wstr.resize(size);\r\n    size = ::MultiByteToWideChar(CP_ACP, 0, str.c_str(), str.size(), const_cast<wchar_t*>(wstr.data()), size);\r\n    if (!size)\r\n    {\r\n        swprintf_s(BUFFER, L\"error,%d\", HRESULT_FROM_WIN32(GetLastError()));\r\n        OutputDebugString(BUFFER);\r\n    }\r\n}\r\n\r\n\r\nvoid tbsinak::_loadfile2()\r\n{\r\n    using Type = decltype(std::chrono::system_clock::now());\r\n    Type now;\r\n    Type end;\r\n    std::chrono::duration<double> diff = {};\r\n    wchar_t buffer[200] = {};\r\n    std::ifstream in(\"dummy.txt\");\r\n    auto const start_pos = in.tellg();\r\n#undef max\r\n    in.ignore(std::numeric_limits<std::streamsize>::max(),-1);\r\n    auto const char_count = in.gcount();\r\n    in.seekg(start_pos);\r\n    auto s = std::string(char_count, char{});\r\n    // or std::vector<char>(char_count);\r\n    // or you can use unsigned char or signed char\r\n    in.read(&s[0], s.size());\r\n    std::wstring wstr(L\"\", 0);\r\n    memset(buffer, 0, sizeof(wchar_t) * 200);\r\n    Timing(now, end, diff, toUSC2(s,wstr), buffer, L\"reencoding\");\r\n    memset(buffer, 0, sizeof(wchar_t) * 200);\r\n    Timing(now, end, diff, this->tb.append(wstr, false), buffer, L\"append to textbox\");\r\n}\r\n\r\n\r\n\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/cnjinhao/nana/issues/comments/346980776","html_url":"https://github.com/cnjinhao/nana/issues/280#issuecomment-346980776","issue_url":"https://api.github.com/repos/cnjinhao/nana/issues/280","id":346980776,"user":{"login":"cnjinhao","id":1246418,"avatar_url":"https://avatars2.githubusercontent.com/u/1246418?v=4","gravatar_id":"","url":"https://api.github.com/users/cnjinhao","html_url":"https://github.com/cnjinhao","followers_url":"https://api.github.com/users/cnjinhao/followers","following_url":"https://api.github.com/users/cnjinhao/following{/other_user}","gists_url":"https://api.github.com/users/cnjinhao/gists{/gist_id}","starred_url":"https://api.github.com/users/cnjinhao/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cnjinhao/subscriptions","organizations_url":"https://api.github.com/users/cnjinhao/orgs","repos_url":"https://api.github.com/users/cnjinhao/repos","events_url":"https://api.github.com/users/cnjinhao/events{/privacy}","received_events_url":"https://api.github.com/users/cnjinhao/received_events","type":"User","site_admin":false},"created_at":"2017-11-26T03:05:58Z","updated_at":"2017-11-26T03:05:58Z","author_association":"OWNER","body":"The pre_calc_line measures the text extent size of a line. If the text box is line-wrapped, it also calculates the number of visual lines that a long width text line takes."}}
{"actor":{"display_login":"cnjinhao"}}