sciter-sdk / go-sciter

Golang bindings of Sciter: the Embeddable HTML/CSS/script engine for modern UI development
https://sciter.com
2.58k stars 268 forks source link

When rendering animation, CPU usage is high #289

Open czxcc opened 3 years ago

czxcc commented 3 years ago

When rendering the animation, the two functions GetMessage/DispatchMessage will take up a lot of CPU time (about 10%).But the CPP version only accounts for about 2%

pravic commented 3 years ago

This better ask on http://sciter.com/forums

czxcc commented 3 years ago

thank you

czxcc commented 3 years ago

for win.GetMessage(msg, 0, 0, 0) > 0 { win.TranslateMessage(msg) win.DispatchMessage(msg) }

The message pump will receive a large number of WM_TIMER messages, but the CPP version will not. Why is this? @pravic

pravic commented 3 years ago

Interesting. I'll check it closely.

Any example to play with?

czxcc commented 3 years ago

``

Interesting. I'll check it closely.

Any example to play with?

example code:

<html>

<head>
<title></title>
<style>
@keyframes breath {
0% {
transform: scale(0.97);
}
70% {
transform: scale(1.03);
}
100% {
transform: scale(0.97);
}
}
.circle {
width: 206dip;
height: 206dip;
border-radius: 103dip;
background-color: rgba(80, 79, 245, 0.27);
box-shadow: 0dip 0dip 6dip 5dip rgba(80, 79, 245, 0.27);
position: absolute;
top: 22dip;
left: 22dip;
transform: scale(0.97);
}
.breath {
animation: 3s infinite ease-in-out breath;
}
</style>
<script type=”text/tiscript”></script>
</head>
<body>
<div class=”circle breath”></div>
</body>
</html>

output message:

/*                                                                                                                                                      
#cgo LDFLAGS: -lUser32                                                                                                                                  
#                                                                                                                                                       
#include <windows.h>                                                                                                                                    
#include <stdio.h>                                                                                                                                      
void run()                                                                                                                                              
{                                                                                                                                                       
    MSG msg;                                                                                                                                            
    while(GetMessage(&msg, NULL, 0, 0) > 0)                                                                                                             
    {                                                                                                                                                   
        fwprintf(stderr, L"message: %d, time: %d\r\n", msg.message, msg.time);                                                                          
        TranslateMessage(&msg);                                                                                                                         
        DispatchMessage(&msg);                                                                                                                          
    }                                                                                                                                                   
}                                                                                                                                                       
*/
import "C"

...

func (s *Window) Run() {                                                                                                                                
    // for system drag-n-drop                                                                                                                           
    // win.OleInitialize()                                                                                                                              
    // defer win.OleUninitialize()                                                                                                                      
    s.run()                                                                                                                                             
    // // start main gui message loop                                                                                                                   
    // msg := (*win.MSG)(unsafe.Pointer(win.GlobalAlloc(0, unsafe.Sizeof(win.MSG{}))))                                                                  
    // defer win.GlobalFree(win.HGLOBAL(unsafe.Pointer(msg)))                                                                                           
    // for win.GetMessage(msg, 0, 0, 0) > 0 {                                                                                                           
    //  win.TranslateMessage(msg)                                                                                                                       
    //  win.DispatchMessage(msg)                                                                                                                        
    // }                                                                                                                                                
    C.run()                                                                                                                                             
}