-
Notifications
You must be signed in to change notification settings - Fork 317
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Performance #8
Comments
So, I set debug level for django_select2 to INFO, and I get the answer, it's the registration process for autofield. In my case, I have |
Also, for convenience in development process, if the registering function must be called once, at the begining, it should be great, but also important, to keep a state of what it does, and not always recall the registering (like having a 'cache' for dev purpose ...) ? |
Hi @ouhouhsami, thanks for finding the cause. Whenever an Auto field is instantiated then it registers itself in a central list. However, if that any other instance of that class has already registered itself then the new instance is not added to the list. So here what happens. Autofield -> Register me -> A unique Id is generated and returned (if that class is already registered then registered unique id for this class is returned) -> Auto field now stores this unique Id. Now whenever the Autofield is rendered then it will pass on this unique Id to rendered markup. The JS helper will send this Id during Ajax lookup. The central View uses the Id to find the appropriate instance to serve the request. Ideally the usual code of a form is like:-
So, when Python parses the above definition it also instantiates |
Thanks for your explanation. The thing is that in development process, I use 3/4 autofield, and the generation of the id take a lot of time the first request (about 30 seconds ...) |
Well then I will need your help then... How many Auto field instances do you have (the count)? I can then profile the time taken when a new one is generated.. and when existing ones are returned.. Will see then where we can optimize. Currently the registration process is minimal. I am suspecting the Dict structure could be causing this delay, as it needs to look inside it first. If that is the case then it will mean delay in serving all auto lookup requests. |
Ok, Here are all my logs INFO Registering auto field: works.fields.WorkSelect2Field So I have 4 auto fields. And here is my code for the WorkSelect2Field
(As you see, I have a related lookup in get_results, but this isn't called on init, I tested) |
Of course |
Well I see about 0.15ms time taken per registration. Your 30s should incude many other stuffs which may not be related to Django Select2. I have made a commit just now to print the time taken in registration. This can be turned on if you set the logger to |
Well, I use your last version, and here is what I get :
The thing is that the debug info is short, the problem is 'just after' : between DEBUG Time taken by synced_f: 0.112 ms and INFO Registering auto field: utils.fields.EquipmentReferenceSelect2Field there is an average 5 seconds (I guess) time lapse. |
Also, I found some kind of a weird bug. If I add, in my case a new Work, next, in a form where I use a WorkSelect2Field, I am able to find it (the Work instance I previously created), but when I save the object (containing reference to the Work instance previously created), the field WorkSelect2Field is empty, even if the data is well saved. If after that I restart server (development or production server), the Work instance is now present in the WorkSelect2Field. It seems like all values available for WorkSelect2Field are kept in a tmp file that is created with the relaunch of the server. But this values are only the ones which where available when the server started, not the one that have been added after. |
As far as the bug goes I will need to investigate that. Are you using app that caches |
Ok, I have a look now at this, but, as I wrote at the begining of this issue, the problem doesn't occur with previous versions of django-select2 (the 2.0.1) |
Ok. I will check again. You also please check and let me know if you find anything interesting. |
So, my first investigation: my problem comes from here : https://github.com/applegrew/django-select2/blob/master/django_select2/fields.py#L431 The 2 things I talked about here have the same issue:
Regards, |
I haven't yet been able to look into this because of my work, and I am going on two weeks vacation. So, there will be considerable delay to fix this. |
Great, I will take a look at your fix ! Thanks. |
@fceruti I took a look at your fix, and it improve a little the thing, but not enough, in my case. Regards, |
As far as I see, the problem would be because something in your code actually evaluate the field's queryset. Try put something like: MyModelField(...): |
@fceruti @ouhouhsami Can u please checkout the latest master branch code and let me know if it addresses ur problems? |
yeah ! First test, and it seems to work now (on my dev setup, not tested yet on our staging), but thanks @applegrew .
|
Cool! Then I can release this version. Closing this bug. |
Hello,
While updating from 2.0.1 to 3.1.2 version (or any of the 3.0 versions), I loose a lot of performance, JUST when I first reach a page of my website after restarting the server (on production), or using python manage.py runserver.
For the moment I didn't investigate much, but is there an initialisation process in django_select2 app done a "first loading" ? And which has changed between 3.0 versions and 2.0.1 version ?
Regards,
The text was updated successfully, but these errors were encountered: