TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Optimizing an Important Atom Primitive

294 pointsby mrboglealmost 10 years ago

18 comments

jerfalmost 10 years ago
You know, it&#x27;s funny how it&#x27;s 2015 and we&#x27;re just dripping with raw power on our developer machines, yet, open a few hundred kilobytes of text and accidentally invoke a handful of O(n^2) algorithms and <i>blammo</i>, there goes all your power. Sobering.<p>Edit: We need a type system which makes O(n^2) algorithms illegal. (Yes... I know what I just dialed up. You can&#x27;t see it, but I&#x27;m giving a very big ol&#x27; evil grin.)
评论 #9729817 未加载
评论 #9728380 未加载
评论 #9727909 未加载
评论 #9727965 未加载
评论 #9728088 未加载
评论 #9728432 未加载
评论 #9730182 未加载
martannealmost 10 years ago
A piece table[0] solves this rather elegantly. Since it is a persistent data structure, a mark can be represented as a pointer into an underlying buffer. If the corresponding text is deleted, marks are updated automatically, since the pointer is no longer reachable from the piece chain. Lookup is linear[1] (or logarithmic if you store pieces in a balanced search tree) in the number of pieces i.e. non-consecutive editing operations.<p>[0] <a href="https:&#x2F;&#x2F;github.com&#x2F;martanne&#x2F;vis#text-management-using-a-piece-tablechain" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;martanne&#x2F;vis#text-management-using-a-piec...</a><p>[1] <a href="https:&#x2F;&#x2F;github.com&#x2F;martanne&#x2F;vis&#x2F;blob&#x2F;master&#x2F;text.c#L1152" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;martanne&#x2F;vis&#x2F;blob&#x2F;master&#x2F;text.c#L1152</a>
评论 #9729876 未加载
dunstadalmost 10 years ago
I tried out Atom a few weeks ago. I loved the UI! Absolutely fantastic, beautiful, nothing but praise there.<p>But I had so many issues with stability, and really missed small but important features that were present in my other editors. I also found that most of the plugins worked either poorly or sporadically.<p>In the end, I decided that it was not worth either using Atom or spending time contributing to it when I have some &quot;pretty close&quot; solutions today. Definitely looking forward to the 1.0 version though, and hats off to all those spending their time contributing to it. I&#x27;m sure it&#x27;s going to become something great!
评论 #9727975 未加载
评论 #9730265 未加载
Veedracalmost 10 years ago
I actually just retried Atom yesterday. Aside from the normal complaints (it&#x27;s sloooww, undo doesn&#x27;t affect markers or selections), one thing that struck me is that markers can&#x27;t be zero-width. Well, they can but they won&#x27;t show up. I&#x27;m wondering if this is related to the technique mentioned here - it&#x27;s certainly been a pain to work around. Sublime Text even has multiple options for this (DRAW_EMPTY and DRAW_EMPTY_AS_OVERWRITE).<p>That said, I&#x27;m loving the API design. Coming from Sublime Text, it&#x27;s a massive upgrade. The ability to embed literally anything a web browser can render in a well-designed framework is mindblowing.
评论 #9728506 未加载
twicalmost 10 years ago
Didn&#x27;t the Xanadu project solve this problem in 1972?<p><a href="https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Enfilade_%28Xanadu%29" rel="nofollow">https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Enfilade_%28Xanadu%29</a><p>Solve it, keep it secret, and then fail to properly write about it to this day.
评论 #9728400 未加载
drewm1980almost 10 years ago
I really, really, don&#x27;t get the whole &quot;implement everything using web technologies&quot; thing. As an outsider from that dev ecosystem it looks like the youtube videos you see of people implementing electronic circuits in Minecraft.
评论 #9730810 未加载
评论 #9730846 未加载
Erwinalmost 10 years ago
If you thought this was an interesting article, here &#x27;s the obligatory link to just about the only book on crafting a text editor, &quot;Craft of Text Editing&quot;: <a href="http:&#x2F;&#x2F;www.finseth.com&#x2F;craft&#x2F;" rel="nofollow">http:&#x2F;&#x2F;www.finseth.com&#x2F;craft&#x2F;</a>
octrefalmost 10 years ago
Recently I learned all contributors will receive a gift for Atom pre-1.0, and when I asked a Github stuff when will I receive the gift (I&#x27;m moving during this summer) he mentioned it would be sent out in early July. I guess we can expect a pre-1.0 before August.<p>One of the main remaining functionality to be implemented is good support for large files. Looking at this issue [1], it seems Atom team is making some progress but there are still some problems to be tackled.<p>In 0.208.0 (released 7 days ago) they mentioned in the changelog <i>Atom now opens files larger than 2MB with syntax highlighting, soft wrap, and folds disabled. We&#x27;ll work on raising the limits with these features enabled moving forward</i>. Little bit disappointed at the progress as you could open large file with these features disabled long time ago through a package &quot;view-tail-large-files&quot;.<p>Just updated to 0.209.0 and using ember.js (1.9 MB) to test. Editing&#x2F;scrolling has some delays but it&#x27;s better than previous versions.<p>Good luck Atom team!<p>[1]: <a href="https:&#x2F;&#x2F;github.com&#x2F;atom&#x2F;atom&#x2F;issues&#x2F;307#event-325455529" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;atom&#x2F;atom&#x2F;issues&#x2F;307#event-325455529</a>
revelationalmost 10 years ago
Yet, the onKeyDown handler still takes 50ms. Are you kidding me? You can push a billion tris in that time.
评论 #9728098 未加载
ohitsdomalmost 10 years ago
Appreciate the candidness of the team writing about their naive approach. Definitely would have been a simpler fix to just search the currently visible text, but I&#x27;m glad they fixed the root issue to make markers more efficient for all.
alexchamberlainalmost 10 years ago
What is the data structure used for the text itself? A rope? The markers could be stored as offsets to the substrings themselves.
msoadalmost 10 years ago
This kind of knowledge and experience exists in Microsoft campus for years thanks to Visual Studio team. That&#x27;s why Code is much more efficient. I only wish if it was open source so I could totally move away from Sublime Text.
评论 #9728725 未加载
romanivalmost 10 years ago
This reminds me of how I re-implemented nested sets in relational databases as spans in a &quot;coordinate&quot; system.<p><pre><code> | Root | | Node | Node| | Node | Node | </code></pre> I stored only &quot;X&quot; and &quot;Y&quot; coordinates for every node, so you had to read &quot;next&quot; node in a row to get current node&#x27;s &quot;size&quot;.<p>It was a bit more human-readable when looking at the data. More importantly, it reduced (on average) the number of nodes I needed to update on insert compared to nested set and gave an easy way of retrieving immediate children. But you still had to &quot;move over&quot; all the nodes &quot;right&quot; of the one you&#x27;re inserting.<p>The structure in the article looks eerily similar. I wonder whether it&#x27;s somehow possible to apply GitHub&#x27;s optimization to this &quot;coordinate&quot; based schema and make it relative without messing up the benefits of column indexing. Hm...
评论 #9728222 未加载
imslavkoalmost 10 years ago
Vim also has a similar optimization: when a file changes, Vim only runs syntax highlighter on a visible part of the text + some buffer in both directions.
评论 #9728115 未加载
caiobalmost 10 years ago
Does it open files &gt;2mb yet? My terminal vim does.
评论 #9728040 未加载
评论 #9728437 未加载
评论 #9729247 未加载
评论 #9728343 未加载
评论 #9728026 未加载
asQuirreLalmost 10 years ago
Hmmm... So the article seems to suggest that for every insertion of a character, a log time lookup is made. Is that really the case? If so, why is the leaf node that the cursor is in not saved? If you were to use a B+-tree implementation then you would already have access to neighbour pointers for rebalancing purposes, making the majority of incremental changes very cheap (constant time). This is just a thought, there may be good reasons why it&#x27;s not possible.
baldfatalmost 10 years ago
Atom is still a hog on my main programing machine. It makes it unusable for me still.<p>It is an OLD i3 Dell from 6 years ago desktop.
评论 #9727903 未加载
评论 #9728650 未加载
评论 #9727819 未加载
评论 #9727814 未加载
z3t4almost 10 years ago
One thing I love about vanilla JS is that you can both set and get with the same property. I wonder if having both setters and getters is enforced by CoffeeScript or a design decision of the Atom team!?