weolar / miniblink49

a lighter, faster browser kernel of blink to integrate HTML UI in your app. 一个小巧、轻量的浏览器内核,用来取代wke和libcef
Apache License 2.0
7.16k stars 1.07k forks source link

WKE - High CPU usage #596

Open lexesv opened 4 days ago

lexesv commented 4 days ago

Hello.

wke version 1.02 blink build 98096 build time Sat Aug 5 14:09:29 2023

CPU AMD Rizen 7 1700X

In headless mode, even after opening a web page (quite simple Json), the application continues to use the CPU at the level of 2.5-3%

How to solve this problem? Because your WKE browser from the examples does not consume as much CPU.

I provide an approximate code:


int main(int argc, char **argv) {

  char cCurrentPath[FILENAME_MAX];
  GetCurrentDir(cCurrentPath, sizeof(cCurrentPath));
  char dllpath[MAX_PATH];
  strcpy(dllpath, (const char *) cCurrentPath);
  strcat(dllpath, "\\node.dll");

  size_t cSize = strlen(dllpath) + 1;
  wchar_t *wdllpath = (wchar_t *) malloc(sizeof(wchar_t) * cSize);
  mbstowcs(wdllpath, dllpath, cSize);

  HMODULE hMod = LoadLibraryW(wdllpath);
  FN_wkeInitializeEx wkeInitializeExFunc = (FN_wkeInitializeEx) GetProcAddress(hMod, "wkeInitializeEx");
  wkeInitializeExFunc((wkeSettings *) 0);
    WKE_FOR_EACH_DEFINE_FUNCTION(WKE_GET_PTR_ITERATOR0, WKE_GET_PTR_ITERATOR1, WKE_GET_PTR_ITERATOR2,
                                 WKE_GET_PTR_ITERATOR3,
                                 WKE_GET_PTR_ITERATOR4, WKE_GET_PTR_ITERATOR5, WKE_GET_PTR_ITERATOR6,
                                 WKE_GET_PTR_ITERATOR11);
  free(wdllpath);

  // set proxy
  wkeSetProxy(&proxy)

  wkeWebView webView = wkeCreateWebView();
  wkeSetHeadlessEnabled(webView, true);

  wkeOnLoadUrlBegin(webView, LoadUrlBeginCallback, 0);
  wkeOnLoadUrlEnd(webView, LoadUrlEndCallback, 0);

  wkeSetUserAgent(webView, Task_ua);
  wkeSetLanguage(webView, "en-US");

  wkePostURL(webView, "https://httptest.pp.ua/post?=2562228&t=1728567681378", Task_postData, (size_t) strlen(Task_postData));

  wkeRunMessageLoop();
}

bool LoadUrlBeginCallback(wkeWebView webView, void *param, const utf8 *url, wkeNetJob job) {
    wkeNetHookRequest(job);
    wkeNetSetHTTPHeaderField(job, (const wchar_t *) L"accept", (const wchar_t *) L"application/json, text/javascript, /; q=0.01", false);
    wkeNetSetHTTPHeaderField(job, (const wchar_t *) L"x-requested-with", (const wchar_t *) L"XMLHttpRequest", false);
    return false;
}

void LoadUrlEndCallback(wkeWebView webView, void *param, const utf8 *url, wkeNetJob job, void *buf, int len) {
    printf("%s\n", buf);
}
weolar commented 1 day ago

I'm in the process of upgrading the kernel and the performance will get a big boost then. I'll post a version next week that you can try.

lexesv commented 1 day ago

I'm in the process of upgrading the kernel and the performance will get a big boost then. I'll post a version next week that you can try.

Thank you. I will wait.