GithubHelp home page GithubHelp logo

Comments (7)

SmileyChris avatar SmileyChris commented on May 20, 2024

Odd... django-countries doesn't use any database entries. All that is stored in the db is the ISO code. Retrieving the field uses a descriptor that creates a pretty simple Country object, calling str/unicode just returns the code. Calling .name on it just references against a static dictionary of countries to return the actual name.

Not sure why you'd be seeing a large overhead. To be clear, you're just seeing the country codes displayed as text in that column in the admin list view, correct?

from django-countries.

luke3141 avatar luke3141 commented on May 20, 2024

I'm seeing the country names in that column.

from django-countries.

SmileyChris avatar SmileyChris commented on May 20, 2024

Are you using the latest version?

from django-countries.

christianglodt avatar christianglodt commented on May 20, 2024

I'm seeing the same problem here. I just upgraded from 2.0b4 to 2.1.2, and the problem persists.

I have an admin page with one CountryField in list_display and list_filter. According to DDT, with 100 rows, it takes about 3000 ms to load. Without the CountryField in list_display and list_filter, it takes about 120 ms.

I've profiled the page and attached a call-graph picture. The branch on the left shows something going on with the iter method (init.py:45) where I end up with a million calls to ugettext.

django-countries-profile

from django-countries.

SmileyChris avatar SmileyChris commented on May 20, 2024

Thanks for the profiling work, Christian.

It definitely seems that we need to cache the sorted country list against the language used in the current thread, so all future iterations have it presorted. This would tie in nicely with the work being discussed in #44

from django-countries.

vdboor avatar vdboor commented on May 20, 2024

It definitely seems that we need to cache the sorted country list against the language used in the current thread, so all future iterations have it presorted. This would tie in nicely with the work being discussed in #44

It seems to be that both can be done separately, implementing the caching. There is low hanging fruit in the code too, for example Countries.name(..) performs dict(self.countries).get(code, '') every time; the list of tuples is converted to a dict to be thrown away a millisecond later. That kind of thing would also improve the performance.

from django-countries.

SmileyChris avatar SmileyChris commented on May 20, 2024

Optimization has been done, this shouldn't be an issue now.

from django-countries.

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.