From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.ciao.gmane.io!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.bugs Subject: bug#38807: [Feature request]: Support lisp workers like web workers. Date: Thu, 26 Mar 2020 16:44:50 +0200 Message-ID: <837dz79nvh.fsf@gnu.org> References: <83o8vpn8g1.fsf@gnu.org> <87mub9u0ld.fsf@gmx.de> <831rslmxih.fsf@gnu.org> <83lfqslafm.fsf@gnu.org> <83r20jjgg3.fsf@gnu.org> <83png1hyb8.fsf@gnu.org> <83imlrh9ze.fsf@gnu.org> <83d096dswz.fsf@gnu.org> <83lfnscvfi.fsf@gnu.org> <831rphbyuw.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="ciao.gmane.io:159.69.161.202"; logging-data="40036"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 38807@debbugs.gnu.org, michael.albinus@gmx.de, yyoncho@gmail.com To: HaiJun Zhang Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Mar 26 15:45:15 2020 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jHTkx-000AKA-6X for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 26 Mar 2020 15:45:15 +0100 Original-Received: from localhost ([::1]:54692 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jHTkw-0002Jn-5D for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 26 Mar 2020 10:45:14 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:46132) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jHTkl-0002GU-TI for bug-gnu-emacs@gnu.org; Thu, 26 Mar 2020 10:45:05 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jHTkk-0002ct-Lc for bug-gnu-emacs@gnu.org; Thu, 26 Mar 2020 10:45:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:53511) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jHTkk-0002cc-He for bug-gnu-emacs@gnu.org; Thu, 26 Mar 2020 10:45:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1jHTkk-0005sb-EB for bug-gnu-emacs@gnu.org; Thu, 26 Mar 2020 10:45:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 26 Mar 2020 14:45:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 38807 X-GNU-PR-Package: emacs Original-Received: via spool by 38807-submit@debbugs.gnu.org id=B38807.158523390122583 (code B ref 38807); Thu, 26 Mar 2020 14:45:02 +0000 Original-Received: (at 38807) by debbugs.gnu.org; 26 Mar 2020 14:45:01 +0000 Original-Received: from localhost ([127.0.0.1]:59484 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jHTki-0005sB-UR for submit@debbugs.gnu.org; Thu, 26 Mar 2020 10:45:01 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:59204) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jHTkg-0005ru-Nj for 38807@debbugs.gnu.org; Thu, 26 Mar 2020 10:44:59 -0400 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]:35829) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1jHTkb-0002Vq-57; Thu, 26 Mar 2020 10:44:53 -0400 Original-Received: from [176.228.60.248] (port=2789 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1jHTka-0006Jx-HV; Thu, 26 Mar 2020 10:44:52 -0400 In-Reply-To: (message from HaiJun Zhang on Thu, 26 Mar 2020 21:37:39 +0800) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.51.188.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:177743 Archived-At: > Date: Thu, 26 Mar 2020 21:37:39 +0800 > From: HaiJun Zhang > Cc: michael.albinus@gmx.de, 38807@debbugs.gnu.org, yyoncho@gmail.com > > I'm not sure I understand the response. Let me repeat the question: > while the module thread parses JSON, will the main thread wait for it, > or will it do something else? Can you describe how this would work > using some use case where lsp-mode is used, like for completing on > program symbols? > > 1 After user inputs a char, lsp-mode call the module api to setup a completion task. The task has a task id. > The lsp-mode saves the task id as the current task and bind a callback function to it. It then returns. > 2 The module create a task and adds it to its task queue. > 3 The worker thread in the module fetches the task from task queue and executes it. It builds the json-rpc > request and sends it to the lsp server. And then it waits for the reply from the lsp server. > 4 The worker receives the reply from lsp server. It parses the json message and builds the completion > result to a list(in lisp). > 5 The worker thread posts a message to emacs. The message includes the task id and the completion > result. > 6 Emacs receives the message and dispatches it to lsp-mode (by calling a function in lsp-mode). The > function checks that it is the result of the completion ask and call the task callback function which will > popups a menu to display the completion items. If the above describes what happens when the user requests completion, then I deduce that the user waits for the entire process you described to finish, because the user cannot continue without seeing the completion candidates, and those are only available after item 6 above is done. Since the user waits for this job to finish anyway, why does it help to run some of this processing in a separate thread? > It will be good if module thread can post message to lisp thread. It will be > better if module thread can send lisp data within the message to lisp thread. > > Posting messages is possible by writing to a pipe. But I don't think > I understand what you mean by "send Lisp data" -- how (in what form) > can Lisp data be sent? > > It can be the above completion list, a point to a lisp object which can be passed to emacs to for lsp-mode to > use. A Lisp object that is not stored in the data structures maintained by alloc.c is not really a Lisp object that has a meaning for Emacs, I think. > My understanding is that pdumper can serialize and deserialize lisp data. Maybe we can prepare > data with its > format and let it deserialize them. > > But we already do that: the libjansson library "serializes" the data, > and we then deserialize it in Emacs as we get the data from the > library. That deserialization is what takes the time you are trying > to make shorter. > > Before lsp-mode, I used completion tools like irony-mode for c/c++ and gocode for golang. They work very > smoothly. > > Now I have used lsp-mode with emacs-27 or emacs master for several weeks. It doesn’t work as smoothly > as the above tools. It lags. > > I added some debug messages to lsp-mode and see that there are too many(about 10~30) json messages > arrived after I input every char. Emacs has to parse and process all of them on every key pressing. > > For the old completion tools, there are only one or two json messages arrived on every key pressing. > > Maybe it is the problem of the lsp server. But it is hard to modify them. I don't think I understand how this is related to the serialization issue and the pdumper.