Git Product home page Git Product logo

Comments (4)

ptaoussanis avatar ptaoussanis commented on June 16, 2024

Hi Yuri, thanks for getting in touch about this!

A few questions:

  • (This one out of curiosity): are you actually running into perf trouble with Record freezing, or is this just a random optimization you spotted?
  • Have you benchmarked the perf difference? Any idea how much more efficient this'd be?
  • Do you have any reference for .__extmap being stable despite being undocumented? I'm generally inclined to avoid undocumented behaviour unless it's well established as stable.

An alternative to introspecting this at freeze time would be to allow the client code to register the record as freezable, which would introspect the class and record the list of fields once at registration time.

That's an interesting idea. We could potentially also just cache the initial introspection. BTW have you tried writing a custom freezer for your Record type? That's generally the approach I take when I've got type(s) I'll be repeatedly freezing since it gives you full control over which fields are frozen and how.

Cheers :-)

from nippy.

yn avatar yn commented on June 16, 2024

Sorry about the delayed response.

I was benchmarking the performance of freezing records using the default implementation, and it seemed like the code was spending a substantial amount of time in "into", so then I dived into the implementation of Record freezing and saw it there. My implementation is specific in that it is a fairly large tree of records, and into is called recursively because we recursively freeze records

I haven't benchmarked the performance difference.

I found out about __extmap from this discussion: http://stackoverflow.com/questions/4520319/clojure-assigning-defrecord-fields-from-map

The discussion dates from 2010, and __extmap is still the case today, so it seems stable to me.

I haven't tried writing a custom freezer because I use records as typed maps: I know that I will have some fields on a record, guaranteed, but I also assoc many other key-value pairs that are not declared up front, and I want all of them frozen; in my particular case, if I were indeed to write a custom freezer, it would be exactly the mechanism I outlined to you: freeze the known fields, and then freeze the __extmap; and then I would rewrite the "freeze the known fields" part generically as an introspecter.

from nippy.

ptaoussanis avatar ptaoussanis commented on June 16, 2024

No problem, thanks for the detailed follow-up. First step would be to benchmark the difference in freeze+thaw times to see what we're working with, then we can go from there! Cheers :-)

from nippy.

yn avatar yn commented on June 16, 2024

I have avoided solving this problem by decreasing the number of objects that I persist, so this optimization is not really necessary for me anymore.

from nippy.

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.