Code Monkey home page Code Monkey logo

Comments (3)

arjunguha avatar arjunguha commented on May 16, 2024 1

Wow! Thanks! And yes, log time is perfectly fine for the kind of thing I'm doing. I am happy storing spans for the moment, but I look forward to using your patch. :)

from grmtools.

ltratt avatar ltratt commented on May 16, 2024

Hello Arjun :)

If so, I suppose the smart approach is to store a Span, and only invoke line_col when I need to print a location.

It depends a bit on your use case, but commonly "yes". If you only ever want to print line/column for a subset of spans and you rarely do so more than once for each Span, then calling line_col lazily is likely to pay off. Indeed, that's why Span exists: it's a more compact representation than the four usizes that line_col returns, on the expectation that most Spans are thrown away without being converted to line/columns. [At some point, I might even pack Span down into a single machine word, but I haven't had the need to descend to that level of micro-optimisation yet.]

There are probably some use cases where the cost of repeated line_col calls isn't worth it, but I expect they're fairly rare. Also, at least in theory, line_col should have a worst case of O(n) where n is the number of lines in the file, although the current implementation is actually O(2n). If that factor of 2 becomes a bottleneck, reducing it to genuinely O(n) won't be difficult.

from grmtools.

ltratt avatar ltratt commented on May 16, 2024

#229 partially addresses this (and it turns out I got the complexity wrong -- it was worse than I first realised!). I think, in general, line_col is now adequately fast. It could be further optimised, ever so slightly, but I think we're now firmly in the land of diminishing returns for this function. Hopefully it's fast enough to convince people that it's OK to use :)

from grmtools.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.