Skip to content

[env](compiler)educe template instantiations in datetime floor/ceil functions#61515

Open
Mryange wants to merge 1 commit intoapache:masterfrom
Mryange:env-compiler-datetime_floor_ceil
Open

[env](compiler)educe template instantiations in datetime floor/ceil functions#61515
Mryange wants to merge 1 commit intoapache:masterfrom
Mryange:env-compiler-datetime_floor_ceil

Conversation

@Mryange
Copy link
Contributor

@Mryange Mryange commented Mar 19, 2026

What problem does this PR solve?

function_datetime_floor_ceil.cpp has excessive template instantiation bloat. The class FunctionDateTimeFloorCeil<Flag, PType, ArgNum, UseDelta> has 4 template parameters, producing 192 instantiations. However, all heavy computation functions (9 vector_* variants, time_round_two_args, floor_opt, etc.) only depend on Flag and PType — they never use ArgNum or UseDelta. This means these expensive functions are compiled 4x more than necessary.

This PR applies three optimizations:

  1. Extract DateTimeFloorCeilCore<Flag, PType> struct: All heavy computation functions are moved into a separate struct with only 2 template parameters. FunctionDateTimeFloorCeil becomes a thin shell that delegates to Core::vector_*(). This reduces instantiations of the heaviest code from 192 → 48 (÷4).

  2. Extract convert_utc_to_local_impl<DateValueType> free function: This function only depends on DateValueType, not Flag/ArgNum/UseDelta. Extracting it reduces its instantiations from 192 → 3.

  3. Extract FunctionDateTimeFloorCeilBase non-template base class: Three virtual overrides (get_number_of_arguments, is_variadic, use_default_implementation_for_nulls) use zero template parameters. Moving them to a non-template base eliminates 192 redundant copies.

Release note

None

Check List (For Author)

  • Test

    • Regression test
    • Unit Test
    • Manual test (add detailed scripts or steps below)
    • No need to test or manual test. Explain why:
      • This is a refactor/code format and no logic has been changed.
      • Previous test can cover this change.
      • No code files have been changed.
      • Other reason
  • Behavior changed:

    • No.
    • Yes.
  • Does this need documentation?

    • No.
    • Yes.

Check List (For Reviewer who merge this PR)

  • Confirm the release note
  • Confirm test cases
  • Confirm document
  • Add branch pick label

@Thearas
Copy link
Contributor

Thearas commented Mar 19, 2026

Thank you for your contribution to Apache Doris.
Don't know what should be done next? See How to process your PR.

Please clearly describe your PR:

  1. What problem was fixed (it's best to include specific error reporting information). How it was fixed.
  2. Which behaviors were modified. What was the previous behavior, what is it now, why was it modified, and what possible impacts might there be.
  3. What features were added. Why was this function added?
  4. Which code was refactored and why was this part of the code refactored?
  5. Which functions were optimized and what is the difference before and after the optimization?

@Mryange
Copy link
Contributor Author

Mryange commented Mar 19, 2026

run buildall

@doris-robot
Copy link

TPC-H: Total hot run time: 26664 ms
machine: 'aliyun_ecs.c7a.8xlarge_32C64G'
scripts: https://github.com/apache/doris/tree/master/tools/tpch-tools
Tpch sf100 test result on commit 2cf44fee6924a6ae3dd2f2c379bf276a4295394c, data reload: false

------ Round 1 ----------------------------------
orders	Doris	NULL	NULL	0	0	0	NULL	0	NULL	NULL	2023-12-26 18:27:23	2023-12-26 18:42:55	NULL	utf-8	NULL	NULL	
============================================
q1	17613	4388	4299	4299
q2	q3	10645	778	527	527
q4	4684	360	252	252
q5	7585	1225	1035	1035
q6	189	175	149	149
q7	786	843	667	667
q8	9313	1466	1325	1325
q9	4879	4758	4636	4636
q10	6249	1926	1634	1634
q11	469	258	239	239
q12	690	576	459	459
q13	18049	2965	2154	2154
q14	227	226	217	217
q15	q16	721	751	659	659
q17	727	823	467	467
q18	5908	5321	5267	5267
q19	1172	970	615	615
q20	557	494	378	378
q21	4576	1841	1382	1382
q22	351	303	428	303
Total cold run time: 95390 ms
Total hot run time: 26664 ms

----- Round 2, with runtime_filter_mode=off -----
orders	Doris	NULL	NULL	150000000	42	6422171781	NULL	22778155	NULL	NULL	2023-12-26 18:27:23	2023-12-26 18:42:55	NULL	utf-8	NULL	NULL	
============================================
q1	4780	4666	4579	4579
q2	q3	3876	4359	3814	3814
q4	879	1194	779	779
q5	4079	4372	4328	4328
q6	193	173	142	142
q7	1776	1668	1543	1543
q8	2477	2687	2509	2509
q9	7662	7356	7712	7356
q10	3743	4005	3662	3662
q11	510	441	417	417
q12	488	596	432	432
q13	2730	3142	2421	2421
q14	302	320	288	288
q15	q16	763	774	720	720
q17	1152	1393	1341	1341
q18	6952	6800	6732	6732
q19	935	887	946	887
q20	2075	2192	2233	2192
q21	3979	3510	3372	3372
q22	460	429	380	380
Total cold run time: 49811 ms
Total hot run time: 47894 ms

@doris-robot
Copy link

TPC-DS: Total hot run time: 169658 ms
machine: 'aliyun_ecs.c7a.8xlarge_32C64G'
scripts: https://github.com/apache/doris/tree/master/tools/tpcds-tools
TPC-DS sf100 test result on commit 2cf44fee6924a6ae3dd2f2c379bf276a4295394c, data reload: false

query5	4359	651	531	531
query6	364	237	223	223
query7	4218	493	274	274
query8	364	263	249	249
query9	8715	2768	2737	2737
query10	553	414	349	349
query11	6966	5096	4901	4901
query12	185	137	127	127
query13	1283	467	356	356
query14	5781	3748	3513	3513
query14_1	2924	2815	2810	2810
query15	206	193	179	179
query16	1032	495	489	489
query17	1121	737	641	641
query18	2697	461	353	353
query19	224	215	190	190
query20	139	131	128	128
query21	216	140	111	111
query22	13276	14182	14578	14182
query23	16352	15772	15619	15619
query23_1	15824	15535	15418	15418
query24	7380	1623	1289	1289
query24_1	1253	1230	1228	1228
query25	548	481	411	411
query26	1225	267	149	149
query27	2767	474	293	293
query28	4433	1853	1868	1853
query29	847	563	499	499
query30	289	227	189	189
query31	1001	960	877	877
query32	81	72	77	72
query33	522	336	315	315
query34	905	922	539	539
query35	660	695	611	611
query36	1065	1107	969	969
query37	152	95	85	85
query38	2961	2977	2864	2864
query39	849	847	819	819
query39_1	794	796	795	795
query40	244	157	140	140
query41	63	62	60	60
query42	277	259	254	254
query43	247	241	222	222
query44	
query45	196	187	183	183
query46	884	990	605	605
query47	2116	2141	2796	2141
query48	312	310	228	228
query49	642	473	395	395
query50	701	280	215	215
query51	4158	4051	4011	4011
query52	298	290	256	256
query53	319	370	310	310
query54	305	287	267	267
query55	94	87	85	85
query56	324	332	344	332
query57	2020	1699	1642	1642
query58	294	280	278	278
query59	2798	2949	2930	2930
query60	350	361	335	335
query61	160	160	161	160
query62	651	590	539	539
query63	316	280	279	279
query64	5059	1299	1003	1003
query65	
query66	1411	452	387	387
query67	25281	24789	25007	24789
query68	
query69	416	349	302	302
query70	1039	971	923	923
query71	339	318	316	316
query72	2693	2816	2381	2381
query73	540	543	328	328
query74	10007	9942	9544	9544
query75	2903	2752	2469	2469
query76	2291	1058	691	691
query77	367	379	326	326
query78	11352	11113	10432	10432
query79	1188	763	581	581
query80	1372	644	534	534
query81	560	273	232	232
query82	980	163	122	122
query83	338	265	257	257
query84	252	124	108	108
query85	934	510	459	459
query86	425	305	257	257
query87	3170	3148	2978	2978
query88	3610	2692	2678	2678
query89	436	368	342	342
query90	2053	184	182	182
query91	177	161	140	140
query92	80	77	73	73
query93	1013	831	503	503
query94	651	313	271	271
query95	596	340	341	340
query96	654	514	233	233
query97	2468	2514	2374	2374
query98	238	222	223	222
query99	1015	983	892	892
Total cold run time: 251790 ms
Total hot run time: 169658 ms

@doris-robot
Copy link

BE UT Coverage Report

Increment line coverage 🎉

Increment coverage report
Complete coverage report

Category Coverage
Function Coverage 52.72% (19788/37532)
Line Coverage 36.24% (184729/509682)
Region Coverage 32.48% (142975/440261)
Branch Coverage 33.67% (62563/185793)

@hello-stephen
Copy link
Contributor

BE Regression && UT Coverage Report

Increment line coverage 100% (0/0) 🎉

Increment coverage report
Complete coverage report

Category Coverage
Function Coverage 71.52% (26273/36735)
Line Coverage 54.39% (276267/507968)
Region Coverage 51.40% (228377/444307)
Branch Coverage 53.00% (98722/186275)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants