From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Theodor Thornhill Newsgroups: gmane.emacs.devel Subject: Re: Tree-sitter indentation for js-mode & cc-mode Date: Fri, 28 Oct 2022 11:10:18 +0200 Message-ID: <87mt9ggvph.fsf@thornhill.no> References: <9AF8BFDC-C9A2-4AE5-A8D2-E6AA05DA3C91@gmail.com> <87k04lljh6.fsf@thornhill.no> <541CF451-6FAC-4531-A8AF-8C86FBB9D40B@thornhill.no> <425E0075-3F44-4832-BA2E-61E7D0A26FF4@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="34330"; mail-complaints-to="usenet@ciao.gmane.io" Cc: emacs-devel , Stefan Monnier To: Yuan Fu Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Fri Oct 28 11:11:33 2022 Return-path: Envelope-to: ged-emacs-devel@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 1ooLOm-0008lx-Sb for ged-emacs-devel@m.gmane-mx.org; Fri, 28 Oct 2022 11:11:33 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ooLNl-0005SR-LI; Fri, 28 Oct 2022 05:10:29 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ooLNj-0005SC-Cs for emacs-devel@gnu.org; Fri, 28 Oct 2022 05:10:27 -0400 Original-Received: from out0.migadu.com ([2001:41d0:2:267::]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ooLNh-0005oQ-AP for emacs-devel@gnu.org; Fri, 28 Oct 2022 05:10:27 -0400 X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=thornhill.no; s=key1; t=1666948221; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=RaXxl1VZ31AfdYlUdmCBBJ1P53hm9XJY6Gzuxs9sZ4E=; b=S/+14HZfDCjP/6U7cdVpFy0Xd0vc4eCwV7F9KvgrzWup/+eT8JJ6axlpWwMmLNMAm55/rT p3m4XpaxNlz1El0eaMQ10brpJCWApIBwc6UT9765wKB3nlxcBGpMeU8rejLGzgdocG7ZH6 ehbCRDb+DOLw24+wAJOPDf2aX1MyfK+HVtgIyxsUCO2plxhmLpAhLWZ1e5WPjIMqecenxm vwtTm+20ilfg0lzs7DzjUfjx2I81KPiy1RPacQbKG734+EekFDQCVMEmHuszawtWQtf1OI xZ015rOOpxGDp+OVGbzBmfM2hdwdkI4F7ioeMlTBqhUGDhWDtejm+Nt5YpyPBg== In-Reply-To: <425E0075-3F44-4832-BA2E-61E7D0A26FF4@gmail.com> X-Migadu-Flow: FLOW_OUT Received-SPF: pass client-ip=2001:41d0:2:267::; envelope-from=theo@thornhill.no; helo=out0.migadu.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: "Emacs-devel" Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:298667 Archived-At: Yuan Fu writes: >>=20 >>>> looking up way to much the root of the tree, but you know the internals >>>> here better than me. Is this something we can optimize away? See the >>>> attached report at the bottom. >>>=20 >>> This is very strange, I need to look into it. >>>=20 >>=20 >> I'm happy to provide more info and profiling, as well as testing if need= be!=20 > > I just tried running treesit-buffer-root-node and treesit-node-at > 10000 times in the end of buffer and they are pretty fast, so I don=E2=80= =99t > know why the benchmark says 99% time is spent in > treesit-buffer-root-node. Could you share the benchmark code and test > file? Thanks! > > Yuan Absolutely. I ran the test again - see test file and new report in attachments. You need to `M-x eval-buffer` in `treesit.el` to avoid the compiled functions to get better profile report, then in the testfile: M-x profiler-start C-x h ;; (mark-whole-buffer) C-i ;; (indent-for-tab-command) ;; --- waaaaait M-x profiler-stop M-x profiler-report There's no test code for this, just running the commands sequentially and get the report :-) Are we parsing the whole file over and over in treesit-buffer-root-node? Do we for some reason not hit the early return? The js-file [0] is taken from [1] and duplicated and messed up indentation. Report [2] was messed up by dpaste it seems. Gmail didn't want the files as attachments, so paste it is :-) Hope this is useful! Theo [0]: https://dpaste.org/dwj3Q [1]: https://raw.githubusercontent.com/TheAlgorithms/JavaScript/master/Sear= ch/BinarySearch.js [2]: https://dpaste.org/aogkm Theo